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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 April 2012 10:31, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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]) > -37LZGFau30o@public.gmane.org = 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Apr 10, 2012 at 6:31 AM, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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]) > -37LZGFau30o@public.gmane.org = 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. >Showing something is a matter of your View. Just use the association, as Colin said, when building the HTML, -- Leonardo Mateo. There''s no place like ~ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 April 2012 10:31, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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]) > -37LZGFau30o@public.gmane.org = current_user.usernameI don''t understand that, what is @user and why are you trying to set its id to the name of the current user? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
i want to have the name of the user who created the each post under their post, what i have now in my view only shows the post, can u help me wit this Colin Law wrote in post #1055779:> On 10 April 2012 10:31, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> format.html >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > > > -- > gplus.to/clanlaw-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think what i wrote there is rubbish, just ignore it and if you have a better method pls put me through, thanks Colin Law wrote in post #1055788:> On 10 April 2012 10:31, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> format.html >> end >> end >> >> def create >> @post = current_user.posts.create(:message => params[:message]) >> @user.id = current_user.username > > I don''t understand that, what is @user and why are you trying to set > its id to the name of the current user? > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 April 2012 11:14, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: Please don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate points in previous message. Thanks> i want to have the name of the user who created the each post under > their post, what i have now in my view only shows the post, can u help > me wit thisI said how to do this already. In your view at some point you have a variable this_post or just post or something. The user created that post will be this_post.user and the name, presumably, is this_post.user.name. I suggest that you work through some rails tutorials to get a grasp of the basics. railstutorial.org is good and is free to use online. Work right through it doing all the exercises and so on. Also look at the Rails Guides. Colin> > > Colin Law wrote in post #1055779: >> On 10 April 2012 10:31, deee el <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> format.html >>> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >> >> >> -- >> gplus.to/clanlaw > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.