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

时间:2015-10-19 18:53:20

标签: ruby-on-rails carrierwave

我真的被困在这里,而且我不确定是怎么回事。

我试图上传图片,但是当我提交表单时,我收到错误:

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'

这是控制器中抛出错误的部分:

 # 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

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

由于

1 个答案:

答案 0 :(得分:3)

原来我在carrierwave初始化器上输了一个错字 '配置/初始化/ carrierwave.rb'

config.storage = 'file'

应该是

config.storage = :file

面掌