I''m currently using Authlogic to authenticate my app. I have a accounts and user model, where accounts has_many :users and user belongs_to :account. I''m having trouble understanding how I should logically add this functionality into my app. "User creates a new account; creating a new account and an admin account. User can add additional users to his account at a later time." I know I should have a user model. At the moment, I have it simple create a new record with timestamps. I then need to associate each user with an account_id, where I''ve created in a new migration to add that column to the user table. My routes are working, and in the console I can see user.account and account.users just fine. I''m stuck at how I''m supposed to add the creation on the new account in my user > create method. Anyone have any clues or can maybe point me in the right direction? -- 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.
Steve Castaneda wrote:> "User creates a new account; creating a new account and an admin > account. User can add additional users to his account at a later time."...should actually read: "User creates a new account; thereby creating a new account and an admin user. User can add additional users to his account at a later time." Sorry about that. -- 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.
Sorry Steve but I don''t really understand this: " I''m stuck at how I''m supposed to add the creation on the new account in my user > create method." What do you mean by this. Can you write more text? Some prose, or some scenarios to make it more clear to me? As for now I would do something like this, but I''m really not sure whether I didn''t miss your point: ... def user=User.new(params[:user]) account = Account.new #and then connect them together. Don''t know how your form looks like. Does your accounts have names than you could do Account.new(params[:account]) or some other variantions end ... Thanks, Chris -- 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.
Steve Castaneda wrote:> My routes are working, and in the console I can see user.account and > account.users just fine. I''m stuck at how I''m supposed to add the > creation on the new account in my user > create method.There are a few ways you could accomplish this. One way would be to use nested routes. Make User nested under Account. That way you''ll have access to the account when you need to add users to the account: POST: http://localhost:3000/accounts/1/users This could be used to add the users to the account later. For the case where you need to create a new Account and your first "admin" User. You could create both during the signup process in the accounts_countoller #create action: @account = Account.new(...account params...) @account.users.build(...user params...) @account.save Or something to that effect. -- 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.