Carl Johnson
2006-Aug-24 08:01 UTC
[Rails] Re: Displaying only that data which is associated to logged
> Now, when I have to show only those courses associated to the who logged > in is by putting a SQL statement which will be "SELECT * FROM courses > WHERE user_id = session[''user''].id" ... am i right?This is precisely the kind of SQL that RoR tries to make unnecessary. To show the user''s courses (assuming you have a ''name'' field in each course) try something like: in controller: @courses = current_user.courses.find_all in view: <% @courses.each do |c| %> <%= c.name<br> %> <% end %> -- 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 -~----------~----~----~----~------~----~------~--~---