这是我尝试更新Vendor
模型上记录的非图片属性时遇到的错误(例如owner
):
NoMethodError at /admin/vendor/12/edit
Message undefined method `thumb_image_changed?' for #<Vendor:0x007ff47d097468>
File /.rvm/gems/ruby-1.9.3-p194@my-app/gems/activemodel-3.2.8/lib/active_model/attribute_methods.rb
Line 407
因此,即使我没有更改图像,也会生成此错误。
这是我Vendor
模型的样子:
class Vendor < ActiveRecord::Base
attr_accessible :name, :description, :banner_image, :logo_image, :intro_text, :thumb_image, :category_ids, :product_ids, :user_id, :remove_banner_image, :banner_image_cache, :remove_logo_image, :logo_image_cache
mount_uploader :banner_image, ImageUploader
mount_uploader :logo_image, ImageUploader
mount_uploader :thumb_image, ImageUploader
has_many :products, :dependent => :destroy
has_many :categories, :through => :products
belongs_to :owner, :class_name => "User",
:foreign_key => "user_id"
end
当我尝试更新记录中的一个图像(而不是全部3个图像)时,我认为出现了类似的错误。
可能导致此问题的原因以及如何解决?
感谢。
修改1:
Vendor#update
控件看起来像一个正常的脚手架update
操作:
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
以下是生成此请求的参数:
Started PUT "/vendors/12" for 127.0.0.1 at 2013-01-06 16:51:28 -0500
Processing by VendorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"3bl5Q=", "vendor"=>{"name"=>"Die", "intro_text"=>"Toppa top jeans", "description"=>"The best jeans you can get your legs in."}, "commit"=>"Update Vendor", "id"=>"12"}
Category Load (13.0ms) SELECT "categories".* FROM "categories" LIMIT 6
Vendor Load (0.1ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = ? LIMIT 1 [["id", "12"]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 51ms
在这种情况下,我正在更新的属性是name
属性。
此外,对于它的价值,这里是一个完整的stack trace of this request。
答案 0 :(得分:2)
您确定vendors
表格中有一个名为thumb_image
的列吗?因为ActiveModel::Dirty看起来真的试图在现有列上运行..._changed?
方法