[英]Undefined method with alias_method_chain
My model has attribute html. 我的模型具有html属性。 When I try to use alias_method_chain with setter html=, I get the error
undefined method `name=' for class `Banner'
But I use alias_method_chain with another attribute. 当我尝试使用带有setter html =的alias_method_chain时,出现
undefined method `name=' for class `Banner'
的错误undefined method `name=' for class `Banner'
但是我将alias_method_chain与另一个属性一起使用。
class Banner < ActiveRecord::Base
def file_with_metadata_handling=(uploaded_file)
# ...
end
def html_with_format_checking=(banner_html)
# ...
end
# works well
alias_method_chain :file=, :metadata_handling
# undefined method html=
alias_method_chain :html=, :format_checking
end
Method is defined 方法已定义
Banner.new.respond_to? :html=
=> true
Model defines attribute's getters & setters dynamically. 模型动态定义属性的获取器和设置器。 So alias_method_chain had't found setter for attribute.
因此alias_method_chain找不到属性的设置器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.