This is a general questions, but one that I have tested and think I know the answer to but..... Lets say I have a table called Users and I create an object to store data for a user in an object called @user. Now, I save that user info by saying ''@user.save''. Now, lets say later on I do a @user User.find_by_id( params[:id] ) which will have the same id for the previous user. And then I say @user.save. If I''m understanding things right, these actiosn will create only one user in the database since they both have the same id''s, but the second save acts as an update? Is this write. The reason I ask is because I am making a form that allows a user to create user information one step at a time. Then at the end all their info is redisplayed and they ''confirm'' that it is write and then any changes that they made, or if they didn''t make any changes, are saved back to the database. I just want to make sure that this will not create multiple entries for the same user. It doesn''t to have done so, but hen again I have not played with it that much. Thanks, --Shandy -- 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 -~----------~----~----~----~------~----~------~--~---
Yes this should work fine. I think the only way you''ll get a new record in the database is when you do @user = User.new and such. Note that you can easily test this with script/console. -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> The reason I ask is because I am making a form that allows a user to > create user information one step at a time. Then at the end all their > info is redisplayed and they ''confirm'' that it is write and then any > changes that they made, or if they didn''t make any changes, are saved > back to the database. I just want to make sure that this will not create > multiple entries for the same user. It doesn''t to have done so, but hen > again I have not played with it that much. Thanks, > > --ShandyI would do @user.update_attributes(params[:user]) ~Jeremy -- 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 -~----------~----~----~----~------~----~------~--~---