Dinshaw Gobhai
2006-Nov-04 00:06 UTC
Last object edited appearing in form on new object page
So my last two projects i keep getting this wierd thing... The last opbejct I created repopulates my edit form when i go to create a new object WITHOUT THE ID BEINNG PASSED. Where is it getting this id from? I have a edit function in my controller ala rails recipies ''cleaning up your controller'' page: def edit #for a parent id @sport = Sport.find(params[:sport_id]) #for a select list @field_types = FieldType.find(:all) @sport_field = SportField.find_by_id(params[:id]) || SportField.new #log output below logger.error(@sport_field.id) if request.post? @sport_field.attributes = params[:sport_field] @sport.sport_fields << @sport_field redirect_to :action => "list", :sport_id => params[:sport_id] and return if @sport_field.save end end So if i hit my list page and then click the new link (<%= link_to "New field for: #{@sport.name}", :action => ''edit'', :sport_id => @sport.id %>) everything is cool and my new object is created and saved, I am redirected back to the list page Now if I hit new again it somehow finds the last object i created and popuates the field values AND the form action with the id of the previous object. This is the wierdest thing.... the log file: ----- Processing SportFieldController#edit (for 127.0.0.1 at 2006-11-03 18:57:09) [GET] Session ID: 5d3f3c4e8af29b3ad4dc5da66034a1cd Parameters: {"action"=>"edit", "sport_id"=>"9", "controller"=>"admin/sport_field"} Sport Columns (0.008294) SHOW FIELDS FROM sports Sport Load (0.006463) SELECT * FROM sports WHERE (sports.id = 9) FieldType Load (0.000939) SELECT * FROM field_types SportField Columns (0.007362) SHOW FIELDS FROM sport_fields SportField Load (0.007752) SELECT * FROM sport_fields WHERE (sport_fields.`id` IS NULL ) LIMIT 1 41 Rendering within layouts/main Rendering admin/sport_field/edit ------ So it selects the opject with ID NULL but finds and logs a id of 40 (in this case) I have switched to database session mgmt just in case. No change. Anybody seen this before? Thanks, -Dinshaw -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-04 01:49 UTC
Re: Last object edited appearing in form on new object page
Dinshaw Gobhai wrote:> @sport_field = SportField.find_by_id(params[:id]) || SportField.new > > #log output below > logger.error(@sport_field.id) > ... > SportField Load (0.007752) SELECT * FROM sport_fields WHERE > (sport_fields.`id` IS NULL ) LIMIT 1 > 41 > ------ > So it selects the opject with ID NULL but finds and logs a id of 40 (in > this case)Which database adapter and Rails version are you using? In any case it''d be better to switch to: @sport_field = params[:id] ? SportField.find(params[:id]) : SportField.new -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Wayne
2006-Nov-04 07:59 UTC
Re: Last object edited appearing in form on new object page
Dinshaw Gobhai wrote:> This is the wierdest thing.... the log file: > ----- > Processing SportFieldController#edit (for 127.0.0.1 at 2006-11-03 > 18:57:09) [GET] > Session ID: 5d3f3c4e8af29b3ad4dc5da66034a1cd > Parameters: {"action"=>"edit", "sport_id"=>"9", > "controller"=>"admin/sport_field"} > Sport Columns (0.008294) SHOW FIELDS FROM sports > Sport Load (0.006463) SELECT * FROM sports WHERE (sports.id = 9) > FieldType Load (0.000939) SELECT * FROM field_types > SportField Columns (0.007362) SHOW FIELDS FROM sport_fields > SportField Load (0.007752) SELECT * FROM sport_fields WHERE > (sport_fields.`id` IS NULL ) LIMIT 1 > 41 > Rendering within layouts/main > Rendering admin/sport_field/edit > > ------ > So it selects the opject with ID NULL but finds and logs a id of 40 (in > this case)Sounds bizarre. There is a plugin called query trace: http://www.agilewebdevelopment.com/plugins/querytrace It places a little call stack in you log file by each sql statement. This should tell you where these queries are getting called from at least. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dinshaw Gobhai
2006-Nov-07 15:18 UTC
Re: Last object edited appearing in form on new object page
Hi and thanks for the reply. I am using mysql and i checked out the head of the repository into vendor at the begining of this month. Here is something else strange, if you refreash the page that has the phantom object''s info, it goes away and acts as if (correctly) I was createing a new object. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-07 17:29 UTC
Re: Last object edited appearing in form on new object page
Dinshaw Gobhai wrote:> Hi and thanks for the reply. > I am using mysql and i checked out the head of the repository into > vendor at the begining of this month. > > Here is something else strange, if you refreash the page that has the > phantom object''s info, it goes away and acts as if (correctly) I was > createing a new object.The reason for what you''re seeing was just described in another thread: http://www.ruby-forum.com/topic/70940#164187 So change your code in the way suggested in this post, which is the same as I suggested in my original reply. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dinshaw Gobhai
2006-Nov-07 17:44 UTC
Re: Last object edited appearing in form on new object page
Mark Reginald James wrote:> So change your code in the way suggested in this post, which is > the same as I suggested in my original reply. >Thank you very much Mark. I was heistant to change that because it is straight out ot Rails Recipies. I will plug in your fix as soon as I am off the clock. Thanks again -Dinshaw -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---