Hi,
I working on a rating system for the posts on my blog:
My tables are
posts
- id
- title
- date
and
ratings
- id
- post_id
- rating
If have these models
class Rating < ActiveRecord::Base
belongs_to :post
end
and
class Post < ActiveRecord::Base
has_one :rating
end
Now in my controller and want to load also the rating for a post:
Controller:
def index
@post_pages, @posts = paginate(:posts, :order => ‘date DESC’)
end
Index.rhtml
<% for post in @posts %>
<%= post.title %>
<%= post.post %>
<%= post.rating.rating %>
How can I get the last line to work?
Thanks,
MJ