Colin Law wrote:
> On 30 March 2010 19:20, Stephen None <lists@ruby-forum.com> wrote:
>> � �@book.update_attributes(params[:book])
>>
>> Processing BooksController#update (for 10.0.1.65 at 2010-03-30 14:01:07)
>> [POST]
>> �Parameters: {"commit"=>"Update", "action"=>"update",
>> "authenticity_token"=>"vq6j9DJ57+AP4kbdbFHjeqeXHiYJDr9RT+zwHVCJ7mI=",
>> "book"=>{"bounceback"=>"1", "barcode"=>"123456789"},
>> "controller"=>"books"}
>
> Look carefully at the params, you will see that you want
> params[:book][:barcode] in your find.
>
> You could have found this by using ruby-debug to break into your
> controller where it is failing and inspecting the variables. See the
> guide on debugging.
>
> I would have expected to see an id there also, are you not passing the
> record up to the view where the form_for is? Look at the code in the
> controller#edit and view#edit and copy those except for missing out
> the fields that you don't want in the view. Then you should get the
> id also and can lookup on that rather than the barcode, which would be
> more conventional. Unless I am misunderstanding exactly what you are
> doing (which would not be unusual).
>
> By the way, could you not 'top post' it would make it easier to follow
> the thread. Thanks.
>
> Colin
That worked great; I will post the final controller in case anyone else
wants to do it but that is pretty cool. I am not using the key field
because the form is on the index page - not the edit page - which means
the record hasn't actually been selected at that point. The barcode
field is unique but not the key field because I need to be able to store
alphanumeric information as part of the barcode and the id field is an
integer. While not necessarily in the spirit of ruby, doing this allows
me to arbitrarily update any record in the database from anywhere in my
application regardless of any nesting or other model complexities.
Thanks for the help, just a couple more problems and my first real app
will be done!
--
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@googlegroups.com.
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.
No comments:
Post a Comment