Hey, I made my authentication system using Authlogic, and I have a current_user helper Now, I also made a scaffold called posts, and everytime a user creates a post using that scaffold, i want it to be assigned to that particular user. So i can render out the posts that ONLY that user made. Now, the question is what to do in the forms, and what to do in the posts controller. Right now, I already have a has_many belongs_to relationship between the too, but i dont know where to go next. What do i have to chnage in the posts controller? What is my post form supposed to look like in order for it to be associated with the current_user? AWww ive been trying to get my mind around this, but i can''t. i need help. really bad. Someone please help. please!! -- 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.
Hey David, It''s really pretty easy and straightforward. In your PostsController: def create @post = current_user.posts.build(params[:post]) if @post.save # ... else # ... end end Also in your PostsController, to list posts only from current_user: def index @posts = current_user.posts end If you want your show method to only look for posts from current_user: def show @post = current_user.posts.find(params[:id]) end /Lasse 2010/3/27 David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Hey, > > I made my authentication system using Authlogic, and I have a > current_user helper > > Now, I also made a scaffold called posts, and everytime a user creates > a post using that scaffold, i want it to be assigned to that > particular user. > > So i can render out the posts that ONLY that user made. > > Now, the question is what to do in the forms, and what to do in the > posts controller. > > Right now, I already have a has_many belongs_to relationship between > the too, but i dont know where to go next. What do i have to chnage in > the posts controller? What is my post form supposed to look like in > order for it to be associated with the current_user? > > > AWww ive been trying to get my mind around this, but i can''t. i need > help. really bad. > > Someone please help. please!! > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
horrah! thanks so much, it was the @post current_user.posts.build(params[:post]) that i was stuck on And now, i get it. and now it works. ur a life saver, thanks so much !!!! On Mar 27, 10:26 am, Lasse Bunk <lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey David, > > It''s really pretty easy and straightforward. > In your PostsController: > > def create > @post = current_user.posts.build(params[:post]) > if @post.save > # ... > else > # ... > end > end > > Also in your PostsController, to list posts only from current_user: > > def index > @posts = current_user.posts > end > > If you want your show method to only look for posts from current_user: > > def show > @post = current_user.posts.find(params[:id]) > end > > /Lasse > > 2010/3/27 David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > Hey, > > > I made my authentication system using Authlogic, and I have a > > current_user helper > > > Now, I also made a scaffold called posts, and everytime a user creates > > a post using that scaffold, i want it to be assigned to that > > particular user. > > > So i can render out the posts that ONLY that user made. > > > Now, the question is what to do in the forms, and what to do in the > > posts controller. > > > Right now, I already have a has_many belongs_to relationship between > > the too, but i dont know where to go next. What do i have to chnage in > > the posts controller? What is my post form supposed to look like in > > order for it to be associated with the current_user? > > > AWww ive been trying to get my mind around this, but i can''t. i need > > help. really bad. > > > Someone please help. please!! > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.
Oh, thanks that relaly helped, but one more thing- If i assigned posts to anotherposts, through a has_many :anotherposts and belongs_to :posts relationship, how would i do @post current_user.posts.build(params[:post]) in this situation? Because i dont have the current_user helper anymore, because we are not dealing with users, but with the post that i want to create anotherposts ontop of. so basically instead of the current_user helper, i want to use the post that the anotherposts is being created on. Do you understand? Hit me with more questions if you want :) I really need help, this shouldn''t be difficult at all. Just a minor switch, that i can''t get my mind around. Hope you can help! thanks!! On Mar 27, 10:26 am, Lasse Bunk <lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey David, > > It''s really pretty easy and straightforward. > In your PostsController: > > def create > @post = current_user.posts.build(params[:post]) > if @post.save > # ... > else > # ... > end > end > > Also in your PostsController, to list posts only from current_user: > > def index > @posts = current_user.posts > end > > If you want your show method to only look for posts from current_user: > > def show > @post = current_user.posts.find(params[:id]) > end > > /Lasse > > 2010/3/27 David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > Hey, > > > I made my authentication system using Authlogic, and I have a > > current_user helper > > > Now, I also made a scaffold called posts, and everytime a user creates > > a post using that scaffold, i want it to be assigned to that > > particular user. > > > So i can render out the posts that ONLY that user made. > > > Now, the question is what to do in the forms, and what to do in the > > posts controller. > > > Right now, I already have a has_many belongs_to relationship between > > the too, but i dont know where to go next. What do i have to chnage in > > the posts controller? What is my post form supposed to look like in > > order for it to be associated with the current_user? > > > AWww ive been trying to get my mind around this, but i can''t. i need > > help. really bad. > > > Someone please help. please!! > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.
bump... :) i really need help guys. On Apr 2, 12:39 pm, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh, thanks that relaly helped, but one more thing- > > If i assigned posts to anotherposts, through a has_many :anotherposts > and belongs_to :posts relationship, how would i do @post > current_user.posts.build(params[:post]) in this situation? Because i > dont have the current_user helper anymore, because we are not dealing > with users, but with the post that i want to create anotherposts ontop > of. > > so basically instead of the current_user helper, i want to use the > post that the anotherposts is being created on. > > Do you understand? Hit me with more questions if you want :) > > I really need help, this shouldn''t be difficult at all. Just a minor > switch, that i can''t get my mind around. Hope you can help! thanks!! > > On Mar 27, 10:26 am, Lasse Bunk <lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > HeyDavid, > > > It''s really pretty easy and straightforward. > > In your PostsController: > > > def create > > @post = current_user.posts.build(params[:post]) > > if @post.save > > # ... > > else > > # ... > > end > > end > > > Also in your PostsController, to list posts only from current_user: > > > def index > > @posts = current_user.posts > > end > > > If you want your show method to only look for posts from current_user: > > > def show > > @post = current_user.posts.find(params[:id]) > > end > > > /Lasse > > > 2010/3/27DavidZhu<dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > Hey, > > > > I made my authentication system using Authlogic, and I have a > > > current_user helper > > > > Now, I also made a scaffold called posts, and everytime a user creates > > > a post using that scaffold, i want it to be assigned to that > > > particular user. > > > > So i can render out the posts that ONLY that user made. > > > > Now, the question is what to do in the forms, and what to do in the > > > posts controller. > > > > Right now, I already have a has_many belongs_to relationship between > > > the too, but i dont know where to go next. What do i have to chnage in > > > the posts controller? What is my post form supposed to look like in > > > order for it to be associated with the current_user? > > > > AWww ive been trying to get my mind around this, but i can''t. i need > > > help. really bad. > > > > Someone please help. please!! > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.