这是我尝试更新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
属性。
此外,对于它的价值,这里是这个请求的完整堆栈跟踪。