Using named_scope in to_json / as_json serialization

Posted by Petr Kaleta on Stack Overflow See other posts from Stack Overflow or by Petr Kaleta
Published on 2010-05-04T21:41:01Z Indexed on 2010/05/04 21:48 UTC
Read the original article Hit count: 196

Filed under:

example: Person has_many Comments. Comments has named_scope :approved. And I need to serialize Person with all approved comments to JSON. So it should look like this:

person.to_json(:include => :comments)

but how can I add there that named scope? To serialize just that approved ones?

© Stack Overflow or respective owner

Related posts about ruby-on-rails