Hi there, I am totally new to Rails, so please forgive me that probably dumb question, but I am stuck with the constellation of having a user and a user_profile model. The idea behind this is to have a user with only the user_id that has_many user_profiles and only the newest user_profile is active. This way I can keep track of all user data changes. But it also requires me to create a new user and a new user_profile in one step. So... do you know a good starting point for doing this? I have set up the relationships and tried to work with <% u.fields_for :user_profile do |p| %> // profile fields here <% end %> nested into the user''s default creation form, but I do not know how to save it in my action (do I have to add something to my model too?). So please, any help is welcome and I assure to ask better questions next time, lol :-) Thanks in advance Arne
Hi-- On Jun 14, 2009, at 1:09 PM, arnekolja wrote:> > Hi there, > > I am totally new to Rails, so please forgive me that probably dumb > question, but I am stuck with the constellation of having a user and a > user_profile model. > > The idea behind this is to have a user with only the user_id that > has_many user_profiles and only the newest user_profile is active. > This way I can keep track of all user data changes. But it also > requires me to create a new user and a new user_profile in one step. > > So... do you know a good starting point for doing this? I have set up > the relationships and tried to work with > > <% u.fields_for :user_profile do |p| %> > // profile fields here > <% end %> > > nested into the user''s default creation form, but I do not know how to > save it in my action (do I have to add something to my model too?). > > So please, any help is welcome and I assure to ask better questions > next time, lol :-) > > Thanks in advance > > Arne >You might want to check this out: http://railscasts.com/episodes/73-complex-forms-part-1 One thing I should mention is that Rails is now supporting a lot of cool complex-form types of stuff so also read this: http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes Hope this helps.
If you are versioning records, as in your UserProfile, then you may want to consider a plugin that does this for you. Consider this: http://github.com/technoweenie/acts_as_versioned/tree/master HTH, Nicholas On Jun 15, 12:49 am, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi-- > > On Jun 14, 2009, at 1:09 PM, arnekolja wrote: > > > > > > > > > Hi there, > > > I am totally new to Rails, so please forgive me that probably dumb > > question, but I am stuck with the constellation of having a user and a > > user_profile model. > > > The idea behind this is to have a user with only the user_id that > > has_many user_profiles and only the newest user_profile is active. > > This way I can keep track of all user data changes. But it also > > requires me to create a new user and a new user_profile in one step. > > > So... do you know a good starting point for doing this? I have set up > > the relationships and tried to work with > > > <% u.fields_for :user_profile do |p| %> > > // profile fields here > > <% end %> > > > nested into the user''s default creation form, but I do not know how to > > save it in my action (do I have to add something to my model too?). > > > So please, any help is welcome and I assure to ask better questions > > next time, lol :-) > > > Thanks in advance > > > Arne > > You might want to check this out: > > http://railscasts.com/episodes/73-complex-forms-part-1 > > One thing I should mention is that Rails is now supporting a lot of > cool complex-form types of stuff so also read this: > > http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nest... > > Hope this helps.