0

I am using Carrierwave & Fog to push images str8 to S3.

The creation action works just fine. The issue is whenever I go to update the record, say change the name attribute, and I don't do anything to the image fields, I get an error that looks like this:

Started PUT "/vendors/7" for 67.230.41.62 at 2012-12-09 07:00:51 +0000
2012-12-09T07:00:51+00:00 app[web.1]:   app/controllers/vendors_controller.rb:65:in `update'
2012-12-09T07:00:51+00:00 app[web.1]: NoMethodError (undefined method `thumb_image_changed?' for #<Vendor:0x00000005940750>):
2012-12-09T07:00:51+00:00 app[web.1]: 
2012-12-09T07:00:51+00:00 app[web.1]:   app/controllers/vendors_controller.rb:66:in `block in update'

My VendorsController#update looks normal:

def update
  @vendor = Vendor.find(params[:id])

respond_to do |format|
  if @vendor.update_attributes(params[:vendor])
    format.html { redirect_to @vendor, notice: 'Vendor was successfully updated.' }
    format.json { head :no_content }
  else
    format.html { render action: "edit" }
    format.json { render json: @vendor.errors, status: :unprocessable_entity }
  end
end

end

The offending line is the update_attributes.

This is my views/vendors/_form.html.erb

<%= simple_form_for(@vendor) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <div class="span8">
        <%= f.input :name, :label => "Vendor Name", :wrapper_html => { :class => "span6" } %>
    </div>
    <div class="span8">
        <%= f.input :intro_text, :label => "The headline for your storefront", :as => :text, :wrapper_html => { :class => "span6" }, :input_html => { :rows => 1 } %>
    </div>    
    <div class="span8">
        <%= f.input :description, :label => "The description of your store", :as => :text, :wrapper_html => { :class => "span6" }, :input_html => { :rows => 5 } %>
    </div>
    <div class="span8">
        <%= f.input :banner_image, :label => "Upload Banner", :wrapper_html => { :class => "span6" } %>    
    </div>
    <div class="span8">
        <%= f.input :logo_image, :label => "Upload Logo", :wrapper_html => { :class => "span6" } %>    
    </div>
    <div class="span8">
        <%= f.button :submit, :class => "btn", :wrapper_html => { :class => "span6" } %>
    </div>
  </div> <!-- /.form-inputs -->


<% end %>

For what it's worth, one of the image sizes in my image_uploader.rb is thumb:

  version :thumb, :from_version => :main_banner do
    process :resize_to_limit => [170, 120]
  end

Thoughts on how I can fix this?

Edit 1

The Vendor model:

class Vendor < ActiveRecord::Base
  attr_accessible :name, :description, :banner_image, :logo_image, :intro_text, :thumb_image
    mount_uploader :banner_image, ImageUploader
    mount_uploader :logo_image, ImageUploader
    mount_uploader :thumb_image, ImageUploader

    acts_as_tagger

    has_many :products

    def tags
        self.owned_tags
    end

    def taggings
        self.owned_taggings
    end
end

Edit 2:

This is what the schema for my Vendor table looks like:

  create_table "vendors", :force => true do |t|
    t.string   "name"
    t.text     "description",  :limit => 255
    t.datetime "created_at",                  :null => false
    t.datetime "updated_at",                  :null => false
    t.string   "banner_image"
    t.string   "logo_image"
    t.string   "intro_text"
  end
marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 1
    my guess is that the error comes from the model. could you post it ? – m_x Dec 09 '12 at 11:53
  • this is weird, and i must admit i don't know where it comes from. I guess you should inspect the source for carrierwave - `thumb_image_changed?` is a magic method that is usually created by [ActiveModel::Dirty](http://api.rubyonrails.org/classes/ActiveModel/Dirty.html), i don't know why it is not automatically created in this case. Stupid question : are your migrations all up-to-date ? – m_x Dec 11 '12 at 09:05
  • @m_x Yes they are. The thing is, in none of my tables is there a `thumb_image` column. That is a carrierwave setting that is specified in the `image_uploader.rb` file that I showed above. I have updated the question to include the schema for my `vendors` file. – marcamillion Dec 11 '12 at 23:16
  • maybe you need this column, the two other pictures have their own. In fact, i think that's the problem : for the two others ActiveRecord automagically creates attribute accessors (and handles dirty state), for this one you have no accessor, not even a virtual attribute accessor. If i remember well, carrierwave mounts itself on an existing accessor... – m_x Dec 13 '12 at 17:29

1 Answers1

0

Turns out that I had to remove the call mount_uploader :thumb_image on my Vendor model because I didn't have a column called thumb_image on that model.

marcamillion
  • 32,933
  • 55
  • 189
  • 380