class Post < ActiveRecord::Base
post.has_many :comments, :as => :commentable
def method_missing(name, *args, &block)
puts "blah!"
end
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
затем в консоли:
>comment.commentable
=> #<Post id: 1022, title: "something">
>comment.commentable.class
=> Post(id: integer, title: string)
>comment.commentable.blah
NoMethodError: undefined method `blah' for "#<Post:0x10f1e9e10>":Post
from /Users/patrick/.rvm/gems/ree-1.8.7-2011.03@myapp/gems/activerecord-3.0.7/lib/active_record/associations/association_proxy.rb:216:in `method_missing'
>Post.find(comment.commentable).blah
=> "blah"
Почему это не работает?