I am a ruby on rails newbie and had a question about the view logic in case of associated objects.
My models look similar to
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
And what I want to display is something like a list of all the posts and the 1st 3 comments for each.
So, I kept the post contoller index action simple
class PostController < ApplicationController
#..
def index
@posts = Post.find(:all)
end
#..
end
Now in the views/posts/index.html.erb
I can do something like this @posts.comments
which I can loop for the 1st 3 entries. But How do I access functionality that is normally done in the model (in this case the associated model) like ordering, scoping etc. in the view (Or controller??)?