Rails 2.3.3
Database and Model Schema
User (id,name,email)
posts (id,subject,message,user_id)
How can I display the name
of the user who has created a particular post?
#posts controller #index action - retrieves all posts in descending order. #I also want it to retrieve user information of that post def index @posts = Post.all( :order => "created_at DESC") respond_to do |format| format.html end end
#partial _post.html.erb Posted by "??how can show the user name here??"
I have modified the user.rb
and post.rb
with active record associations and have set a foreign key. i.e post.user_id
references user.id
.
But how can I display user information for each individual post in the index
action?