私の現在のコード:
class Product < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
def method_missing name
true
end
end
Category.new.ex_undefined_method #=> true
Product.last.category.ex_undefined_method #=> NoMethodError: undefined method `ex_undefined_method' for #<ActiveRecord::Associations::BelongsToAssociation:0xc4cd52c>
これは、モデルに存在するメソッドのみを渡すレール内のこのコードが原因で発生します。
private
def method_missing(method, *args)
if load_target
if @target.respond_to?(method)
if block_given?
@target.send(method, *args) { |*block_args| yield(*block_args) }
else
@target.send(method, *args)
end
else
super
end
end
end
これが私が欲しいものです:
Product.last.category.ex_undefined_method #=> true
どうすればこれを達成できますか?