Ruby on Rails
Friday, June 8, 2018
On Friday, 8 June 2018 23:03:51 UTC+1, Hassan Schroeder wrote:
On Fri, Jun 8, 2018 at 12:54 PM, Robert Phillips
<robert.p...@gmail.com> wrote:
> def edit
> # http://127.0.0.1:3000/bottles/0/edit :id==0
Where in the world are you getting this id of 0 ? What database
are you using? Every DB I've worked with starts an auto-increment
sequence with a positive (e.g. 1 or higher) number...
Thanks, well spotted, that was my mistake / the bug in my program.
The id of the object was 1. But I was going to /bottles/0/edit Then in the edit action I was using that number (0), to identify the object, because I was using that number as an index to the array. Bottles.all[0] So the data from the first bottle was going into the form.
Then, when I click the button to submit the form, it posts to /bottles/1 because it was using the id of @bottle
So I need my edit action to treat the number in the url (the id), as an id and not as an index to an array.
So , in the edit action, I could use @bottle=Bottle.find(...), and then pass in the id to the find method.
So the id in the edit url will then match the id of the object, and then there's no change in id when the form is submitted.
Thanks
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1b2f2788-2906-49cc-97ed-b0e2e236d83b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment