Apparently today I'm the worst developer ever.
Same form I've been working on for 2 days now. I've slimmed it down
now from 4 models to 2 to try and narrow the problem field.
The controller only defines two areas. [new, create]
In my form I have a <%= forms_for :user, @user %> section.
In my controller I have:
@dealer = Dealer.new(params[:dealer])
@user = @dealer.users.new(params[:user])
@user.roles << Role.find(3)
rescue ActiveRecord::RecordInvalid => invalid
render :controller => 'dealers', :action => 'new'
if ! @dealer.new_record? && ! @user.new_record?
flash[:notice] = "Dealer, User and addresses saved!"
What is now happening is if the dealer parameters are wrong. It throws
up validation errors like expected. If the dealer params are correct
but the user params are wrong then as exepcted nothing gets saved to
the db thanks to the transaction. BUT the page gets rendered as an
edit_dealer_id page. with a new hidden field telling the form to
submit via put method. And of course that dealer id doesn't exist as
it never saved to the db.
How is this even happening. I don't have edit/update controller
functions or views. This is just being generated on the fly and is a
really big pain. Why wouldn't it just render the correct page like
when the dealer params are incorrect. Something has gone horribly
wrong somewhere and nothing is working like i'd expect.
Any suggestions would help,