hi there, i have this problem, i am a newb in ror and don''t know how to do this. i have a user_id column in a database table named items, i also use the login generator, i can signup, login, and logout, no problem with it, but when i am logon to the system, and tried to make a new item, the user_id field is null, my user_id is not written in the user_id table, and i have really no idea how to do it. i have associations, has_many :items in user.rb model, and belongs_to :user in item.rb. i know you can help me with this, like i''ve said, i am just learning ror and new to this forum as well. please post your replies on what info you need to help me. thanks in advance. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
You likely want to do something like this is your controller: current_user.items.create(params[:item]) This will automatically set the user_id for you. -- Zack Chandler http://depixelate.com On 3/18/07, Pleigh Ful <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hi there, i have this problem, i am a newb in ror and don''t know how to > do this. i have a user_id column in a database table named items, i also > use the login generator, i can signup, login, and logout, no problem > with it, but when i am logon to the system, and tried to make a new > item, the user_id field is null, my user_id is not written in the > user_id table, and i have really no idea how to do it. i have > associations, has_many :items in user.rb model, and belongs_to :user in > item.rb. > > i know you can help me with this, like i''ve said, i am just learning ror > and new to this forum as well. please post your replies on what info you > need to help me. > > thanks in advance. > > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---
Another option would be to store the user_id in session[:user_id] during login. Then when you create a new object: unless session[:user_id].empty? @thing = Thing.new(params) @thing.user_id = session[:user_id] @thing.save else flash[:notice] = "Log in before creating something!" redirect_to :somewhere 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?hl=en -~----------~----~----~----~------~----~------~--~---
Pleigh Ful wrote:> hi there, i have this problem, i am a newb in ror and don''t know how to > do this. i have a user_id column in a database table named items, i also > use the login generator, i can signup, login, and logout, no problem > with it, but when i am logon to the system, and tried to make a new > item, the user_id field is null, my user_id is not written in the > user_id table, and i have really no idea how to do it. i have > associations, has_many :items in user.rb model, and belongs_to :user in > item.rb. > > i know you can help me with this, like i''ve said, i am just learning ror > and new to this forum as well. please post your replies on what info you > need to help me. > > thanks in advance. > >Try the UserStamp plugin: http://delynnberry.com/projects/userstamp/ HTH Mike --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---