magic6435-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-May-21 15:51 UTC
Multiple Models one form and validations ... no transactions(mongo)
I am trying to setup a sigup form thats pretty much just like the basecamp form. https://signup.37signals.com/basecamp/Plus/signup/new I want to create a User a Studio and a Subscription(chargify) a Subscription belongs to a Studio and not to a User. User gets tagged onto a Studio via an admin array. Is there any way to do this all in one form and still get back validation errors etc without using a transaction to roll everything back? Right now i have the problem where if the User gets created but then the Studio or Subscription fails I then have a User sitting in the db when the form re-renders "new" and they click save again then they will get a error about "username already exists" blah blah blah. Right now i am creating everything via the User model with all the extra fields on attr_accessor and a method called "create_and_subscribe". Is that the best practice for this? and if so how do i still get back the validations from the other model like Studio. Since i don''t have transactions the best i could think of was this at the head of "create_and_subscribe" def create_and_subscribe(product_id) studio = Studio.new(studio_params) return unless self.valid? && studio.valid? ..... ..... end that way i at least know they are valid then i actually create them if the call to Chargify is successful. Thanks for any help this has been driving me nuts. Ps.I wonder if this is better suited to the mongo form since my problem is coming from lack of transactions? -- 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.