简体   繁体   中英

CarrierWave throws NoMethodError - undefined method `new' for “file”:String:

I'm really stuck here, and I'm not sure what's going on.

I'm trying to upload an image, but when I submit the form, I get the error:

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'

This is the part in the controller where its throwing the error:

 # 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 }

My partners view:

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

Model:

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

I'm really stuck here and would appreciate any help/comment/input...

Thanks

Turns out I made a typo on the carrierwave initializer 'config/initializers/carrierwave.rb'

config.storage = 'file'

should have been

config.storage = :file

face-palm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM