gpt4 book ai didi

ruby-on-rails - CarrierWave 抛出 NoMethodError - `new' :String: 的未定义方法 "file"

转载 作者:行者123 更新时间:2023-12-04 11:36:19 25 4
gpt4 key购买 nike

我真的被困在这里,我不确定发生了什么。

我正在尝试上传图片,但在提交表单时出现错误:

Started PATCH "/partners/3" for ::1 at 2015-10-19 14:44:45 -0400
Processing by PartnersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CELmC1ibFcHCYB0avQk632KZzqvLUb125W2b3F2At3pkeAaL7N/aowlGqrd/+vaFV/RZ78z+/lmJc60hNPtrCw==", "partner"=>{"name"=>"Company", "description"=>"We make stuff", "track_id"=>"3"}, "commit"=>"Update Partner", "id"=>"3"}
Partner Load (0.1ms) SELECT "partners".* FROM "partners" WHERE "partners"."id" = ? LIMIT 1 [["id", 3]]
(0.0ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.2ms)

NoMethodError - undefined method `new' for "file":String:
carrierwave (0.10.0) lib/carrierwave/uploader/store.rb:106:in `storage'
carrierwave (0.10.0) lib/carrierwave/uploader/proxy.rb:35:in `identifier'
carrierwave (0.10.0) lib/carrierwave/mount.rb:312:in `write_identifier'
carrierwave (0.10.0) lib/carrierwave/mount.rb:223:in `write_logo_img_identifier'
activesupport (4.2.3) lib/active_support/callbacks.rb:430:in `block in make_lambda'
activesupport (4.2.3) lib/active_support/callbacks.rb:162:in `block in halting'
activesupport (4.2.3) lib/active_support/callbacks.rb:502:in `block in call'
activesupport (4.2.3) lib/active_support/callbacks.rb:502:in `call'
activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks'
activerecord (4.2.3) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.2.3) lib/active_record/persistence.rb:120:in `save'
activerecord (4.2.3) lib/active_record/validations.rb:37:in `save'
activerecord (4.2.3) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.2.3) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
activerecord (4.2.3) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'

这是 Controller 中抛出错误的部分:

 # PATCH/PUT /partners/1
# PATCH/PUT /partners/1.json
def update
respond_to do |format|
>>> HERE >>> if @partner.update(partner_params)
format.html { redirect_to @partner, notice: 'Partner was successfully updated.' }
format.json { render :show, status: :ok, location: @partner }
else
format.html { render :edit }
format.json { render json: @partner.errors, status: :unprocessable_entity }

我的合作伙伴 View :

  <div class="form-group">
<%= f.label :logo_img %>
<%= f.file_field :logo_img %>
</div>

型号:

class Partner < ActiveRecord::Base
belongs_to :track

has_one :question

validates :name, :presence => true
validates :track_id, :presence => true

mount_uploader :logo_img, ImageUploader
end

我真的被困在这里,非常感谢任何帮助/评论/输入......

谢谢

最佳答案

原来我在载波初始化器上打错了字'config/initializers/carrierwave.rb'

config.storage = 'file'

应该是

config.storage = :file

捂脸

关于ruby-on-rails - CarrierWave 抛出 NoMethodError - `new' :String: 的未定义方法 "file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33221769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com