Hey,
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:
begin
ActiveRecord::Base.transaction do
@dealer = Dealer.new(params[:dealer])
@dealer.save
@user = @dealer.users.new(params[:user])
@user.roles << Role.find(3)
@user.save!
end
rescue ActiveRecord::RecordInvalid => invalid
render :controller => ''dealers'', :action =>
''new''
end
if ! @dealer.new_record? && ! @user.new_record?
flash[:notice] = "Dealer, User and addresses saved!"
redirect_to root
end
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,
cheers,
brianp
--
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.
On May 19, 2:36 am, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT the page gets rendered as an > edit_dealer_id page. with a new hidden field telling the form to > submit via put method.I dont really unserstand what you''re saying. What are you expecting to get rendered, and what is actually getting rendered? -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Expecting to get rendered: The same form page I''ve created at the :new action with the Invalid model notices from my model validations. What is getting rendered: A form that LOOKS the same, with my Invalid model notices but now does not POST to the :create action. The form has magically changed my hard coded input to post to the create action into a :put method to the :update action. I know it''s kind of an obscure problem. Maybe later today I''ll post a git repository with the code needed to recreate the problem. On May 19, 1:13 am, Sharagoz <shara...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 19, 2:36 am, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT the page gets rendered as an > > edit_dealer_id page. with a new hidden field telling the form to > > submit via put method. > > I dont really unserstand what you''re saying. What are you expecting to > get rendered, and what is actually getting rendered? > > -- > 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@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 May 2010 16:44, brianp <brian.o.pearce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Expecting to get rendered: The same form page I''ve created at the :new > action with the Invalid model notices from my model validations. > > What is getting rendered: A form that LOOKS the same, with my Invalid > model notices but now does not POST to the :create action. The form > has magically changed my hard coded input to post to the create action > into a :put method to the :update action.Have you checked the html of the page to see exactly what is being generated incorrectly? View, Page Source or similar in browser.> > I know it''s kind of an obscure problem. Maybe later today I''ll post a > git repository with the code needed to recreate the problem. > > On May 19, 1:13 am, Sharagoz <shara...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On May 19, 2:36 am, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT the page gets rendered as an >> > edit_dealer_id page. with a new hidden field telling the form to >> > submit via put method. >> >> I dont really unserstand what you''re saying. What are you expecting to >> get rendered, and what is actually getting rendered? >> >> -- >> 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes I have that''s how I know it''s changing the form method to
PUT to
dealer/id/edit. It''s also adding an id of: edit_dealer_id_{#number}
where {#number} is an actual digit.
On May 19, 9:38 am, Colin Law
<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:> On 19 May 2010 16:44, brianp
<brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Expecting to get rendered: The same form page I''ve created at
the :new
> > action with the Invalid model notices from my model validations.
>
> > What is getting rendered: A form that LOOKS the same, with my Invalid
> > model notices but now does not POST to the :create action. The form
> > has magically changed my hard coded input to post to the create action
> > into a :put method to the :update action.
>
> Have you checked the html of the page to see exactly what is being
> generated incorrectly? View, Page Source or similar in browser.
>
>
>
>
>
> > I know it''s kind of an obscure problem. Maybe later today
I''ll post a
> > git repository with the code needed to recreate the problem.
>
> > On May 19, 1:13 am, Sharagoz
<shara...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >> On May 19, 2:36 am, brianp
<brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT
the page gets rendered as an
> >> > edit_dealer_id page. with a new hidden field telling the form
to
> >> > submit via put method.
>
> >> I dont really unserstand what you''re saying. What are you
expecting to
> >> get rendered, and what is actually getting rendered?
>
> >> --
> >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >> For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > 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
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> 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@googlegroups.com.
> For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
--
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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
I may be wrong, but I think rails uses the new_record? method to decide whether the form should be posted to the create or the update action when you do something like <% form_for(@dealer) do |f| %>. Are you sure your transaction is working correctly and that everything has been rolled back? Can you verify that @dealer.new_record? returns true after the failed transaction? On May 19, 6:44 pm, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes I have that''s how I know it''s changing the form method to PUT to > dealer/id/edit. It''s also adding an id of: edit_dealer_id_{#number} > where {#number} is an actual digit. > > On May 19, 9:38 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > On 19 May 2010 16:44, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Expecting to get rendered: The same form page I''ve created at the :new > > > action with the Invalid model notices from my model validations. > > > > What is getting rendered: A form that LOOKS the same, with my Invalid > > > model notices but now does not POST to the :create action. The form > > > has magically changed my hard coded input to post to the create action > > > into a :put method to the :update action. > > > Have you checked the html of the page to see exactly what is being > > generated incorrectly? View, Page Source or similar in browser. > > > > I know it''s kind of an obscure problem. Maybe later today I''ll post a > > > git repository with the code needed to recreate the problem. > > > > On May 19, 1:13 am, Sharagoz <shara...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> On May 19, 2:36 am, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT the page gets rendered as an > > >> > edit_dealer_id page. with a new hidden field telling the form to > > >> > submit via put method. > > > >> I dont really unserstand what you''re saying. What are you expecting to > > >> get rendered, and what is actually getting rendered? > > > >> -- > > >> 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@googlegroups.com. > > >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.