I started this yesterday but my spam filter at work has blocked anything from this site, so have carried it over to my home email address. Basically I have followed Curt Hibbs article Rolling Ruby on Rails and everything went well until I tried the update. I got the following error. ActiveRecord::RecordNotFound in Recipe#update . Couldn''t find Recipe without an ID Request Parameters: {"recipe"=>{"title"=>"Ice Water", "id"=>"2", "category_id"=>"2", "description"=>"Everyone''s favorite.", "instructions"=>" Put ice cubes in a glass of water.\r\n \r\n "}} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} Duane Johnson responded with: What does your controller code look like? (i.e. the ''update'' method in your controller, or whatever is calling Recipe.update). Also, what version of Rails are you using? My controller uses scaffold for the update function as per the article. At this point I ought to add that I downloaded the source from the article and the exported database, all to no avail. Surely I am not the only one to have followed this article and had this problem? Tobias Luetke said: you got a call like Receipt.find(params[:id]) in your code buy params[:id] is empty. you need to pass an ID to the update action So as before, why have I got this with the original source and no-one else has? The offending code that Tobias questions is: <html> <head> <title>Edit Recipe</title> </head> <body> <h1>Edit Recipe</h1> <form action="../update" method="POST"> <input id="ID" name="recipe[id]" size="30" type="hidden" value="<%= @recipe.id %>" /> <p><b>Title</b><br> <input id="recipe_title" name="recipe[title]" size="30" type="text" value="<%= @recipe.title %>" /> </p> <p><b>Description</b><br> <input id="recipe_description" name="recipe[description]" size="30" type="text" value="<%= @recipe.description %>" /> </p> <p><b>Category:</b><br> <select name="recipe[category_id]"> <% @categories.each do |category| %> <option value="<%= category.id %>" <%= '' selected'' if category.id == @recipe.category.id %>> <%= category.name %> </option> <% end %> </select></p> <p><b>Instructions</b><br> <textarea cols="40" id="recipe_instructions" name="recipe[instructions]" rows="20" wrap="virtual"> <%= @recipe.instructions %> </textarea> </p> <input type="submit" value="Update" /> </form> <a href="/recipe/show/<%= @recipe.id %>"> Show </a> | <a href="/recipe/list"> Back </a> </body> </html> I am getting to my wits end here and am seriously thinking of abandoning rails altogether! Please advise. Cheers Shane
On Jul 26, 2005, at 11:54 AM, Shane wrote:> I started this yesterday but my spam filter at work has blocked > anything from > this site, so have carried it over to my home email address. > Basically I have followed Curt Hibbs article Rolling Ruby on Rails and > everything went well until I tried the update. I got the following > error. > ActiveRecord::RecordNotFound in Recipe#update > > . Couldn''t find Recipe without an ID > > Request > Parameters: {"recipe"=>{"title"=>"Ice > Water", "id"=>"2", "category_id"=>"2", "description"=>"Everyone''s > favorite.", "instructions"=>" Put ice cubes in a glass of water.\r > \n \r\n "}} >From your parameters hash, it shows that you''ve passed params [:recipe][:id] back to your controller, *not* params[:id]. More below.> Response > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > Duane Johnson responded with: > What does your controller code look like? (i.e. the ''update'' method > in your > controller, or whatever is calling Recipe.update). Also, what > version of Rails > are you using? > > My controller uses scaffold for the update function as per the > article. At this > point I ought to add that I downloaded the source from the article > and the > exported database, all to no avail. Surely I am not the only one to > have > followed this article and had this problem?It''s not very useful to just say "it''s as per the article" when only a fraction of us have actually read the article. As good as the article and code itself are, we''ve come here to this list by different paths. In addition, unless I''ve missed some correspondence from you, you didn''t answer my second question--what version of Rails are you using?> Tobias Luetke said: > you got a call like Receipt.find(params[:id]) in your code buy > params[:id] is empty. you need to pass an ID to the update action > > So as before, why have I got this with the original source and no- > one else has? >Not all of us are intimately familiar with the source code, so we''re just trying our best to help :) It''s still a good question though, and one that we''ll hopefully figure out.> The offending code that Tobias questions is: > <html> > <head> > <title>Edit Recipe</title> > </head> > <body> > <h1>Edit Recipe</h1> > > <form action="../update" method="POST"> > <input id="ID" name="recipe[id]" size="30" > type="hidden" value="<%= @recipe.id %>" />It looks like the line above may be the offending line. Change it to: <input id="ID" name="id" size="30" type="hidden" value="<%= @recipe.id %>" /> and that may do the trick. If the update action in your controller is expecting params[:id] to contain the id of the recipe, then you must pass the id in as I''ve shown. Could this be the problem?> > I am getting to my wits end here and am seriously thinking of > abandoning rails > altogether! >Stick it out a little longer... it''ll be worth it. Duane Johnson (canadaduane)
-----Original Message----- From: Duane Johnson [mailto:duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] Sent: 26 July 2005 22:16 To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Cc: Shane Subject: Re: [Rails] Cannot update On Jul 26, 2005, at 11:54 AM, Shane wrote:> I started this yesterday but my spam filter at work has blocked > anything from > this site, so have carried it over to my home email address. > Basically I have followed Curt Hibbs article Rolling Ruby on Rails and > everything went well until I tried the update. I got the following > error. > ActiveRecord::RecordNotFound in Recipe#update > > . Couldn''t find Recipe without an ID > > Request > Parameters: {"recipe"=>{"title"=>"Ice > Water", "id"=>"2", "category_id"=>"2", "description"=>"Everyone''s > favorite.", "instructions"=>" Put ice cubes in a glass of water.\r > \n \r\n "}} >From your parameters hash, it shows that you''ve passed params [:recipe][:id] back to your controller, *not* params[:id]. More below.> Response > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > Duane Johnson responded with: > What does your controller code look like? (i.e. the ''update'' method > in your > controller, or whatever is calling Recipe.update). Also, what > version of Rails > are you using? > > My controller uses scaffold for the update function as per the > article. At this > point I ought to add that I downloaded the source from the article > and the > exported database, all to no avail. Surely I am not the only one to > have > followed this article and had this problem?It''s not very useful to just say "it''s as per the article" when only a fraction of us have actually read the article. As good as the article and code itself are, we''ve come here to this list by different paths. In addition, unless I''ve missed some correspondence from you, you didn''t answer my second question--what version of Rails are you using?> Tobias Luetke said: > you got a call like Receipt.find(params[:id]) in your code buy > params[:id] is empty. you need to pass an ID to the update action > > So as before, why have I got this with the original source and no- > one else has? >Not all of us are intimately familiar with the source code, so we''re just trying our best to help :) It''s still a good question though, and one that we''ll hopefully figure out.> The offending code that Tobias questions is: > <html> > <head> > <title>Edit Recipe</title> > </head> > <body> > <h1>Edit Recipe</h1> > > <form action="../update" method="POST"> > <input id="ID" name="recipe[id]" size="30" > type="hidden" value="<%= @recipe.id %>" />It looks like the line above may be the offending line. Change it to: <input id="ID" name="id" size="30" type="hidden" value="<%= @recipe.id %>" /> and that may do the trick. If the update action in your controller is expecting params[:id] to contain the id of the recipe, then you must pass the id in as I''ve shown. Could this be the problem?> > I am getting to my wits end here and am seriously thinking of > abandoning rails > altogether! >Stick it out a little longer... it''ll be worth it. Duane Johnson (canadaduane) That fixed it! Duane I am forever in your debt! I am a 3GL developer (DBL) tryng to get to grips with new technologies/paradigms. This was really hurting me, more so as everything I have read about rails and ruby has been so positive. I appreciate that its going to be a long ahul getting to be proficient in OO programming but with help like this i know that in the end I will get there. Many thanks Shane -- I am using the free version of SPAMfighter for private users. It has removed 45 spam emails to date. Paying users do not have this message in their emails. Try www.SPAMfighter.com for free now! _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Duane Johnson wrote:> > It''s not very useful to just say "it''s as per the article" when only a > fraction of us have actually read the article. As good as the article > and code itself are, we''ve come here to this list by different paths.Part 2 of the Rolling with Ruby on Rails article has a link to a zip file containing the source code for part 1 (and an export of the database for part 1). I think Duane is saying that he used tried this source code and database and had the same problem (I can successfully run this code with the latest Rails). For the record the code is available here: http://www.onlamp.com/onlamp/2005/03/03/examples/cookbook_part1_0.10.0.zip Anyway Duane, perhaps something is corrupted in your whole setup. You could try to uninstall Ruby, then reinstall Ruby and Rails, and then try the source code referenced above. That at least duplicates the process I went through to verify that the code still works with the latest Rails. Curt