Search code examples
ruby-on-railsruby-on-rails-3carrierwavefog

When updating a _form partial that has an image, but not the image, I get an error


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

Solution

  • 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.