On 10 April 2012 10:31, deee el <[email protected]> wrote: > Please Im trying to create an application where i can post like twitter, > but i was the users name to be posted under their respective posts > > My Post_controller looks like this > def index > @posts = Post.all(:order => "created_at DESC") > @users = User.find(:all) > #@user_id = current_user.find(params[:id]) > > respond_to do |format| > format.html > end > end > > def create > @post = current_user.posts.create(:message => params[:message]) > @user.id = current_user.username > > the models both have the correct association and tables are having > User_id as primary on User table and Foreign on the Post Table, how do > i create a method to be a able to have my index view show the post and > name.
Not sure I understand exactly, but if you have a post in this_post, say, then the user is this_post.user, so the name will be this_post.user.name Colin > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- gplus.to/clanlaw -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

