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

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

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 }

我的合作伙伴观点:
  <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

我真的被困在这里,希望得到任何帮助/评论/输入...

谢谢

最佳答案

原来我在载波初始化器上打错字了
'配置/初始化程序/carrierwave.rb'

config.storage = 'file'

本来应该
config.storage = :file

面掌

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

10-13 04:49