0
與單桌玩圍繞繼承和hstore在軌道4,5的方法,但得到一個錯誤試圖調用方法父時:Rails的NoMethodError時,呼籲家長
# models/item.rb
class Item < ActiveRecord::Base
def getter_setter_for(key)
define_method(key) do
properties && properties[key]
end
define_method("#{key}=") do |value|
self.properties = (properties || {}).merge(key => value)
end
end
end
# models/disk_item.rb
class DiskItem < Item
%w[filename path].each do |key|
getter_setter_for(key) ## <== error calling this method
end
end
錯誤:
Exception encountered: #<NoMethodError: undefined method `getter_setter_for' for #<Class:0x007f8c739a5ae0>>
我忽略了什麼明顯的東西?
doh!謝謝! 'def self.getter_setter_for(key)'修正了它! – Meltemi