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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi, The kind of relation you have within tables, try Rating.find(post.id) regards gaurav On 10/24/06, MJ <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi, I misunderstood your question my previous reply not relevant I apologise regards gaurav --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---