Hi Ma We,
On Tue, Jun 8, 2010 at 5:23 AM, Ma We <[email protected]> wrote:
> The parameters of my update are looking like this:
> Parameters: {"commit"=>"Update", "action"=>"update", "_method"=>"put",
> "authenticity_token"=>"***", "product"=>{"image_url"=>"w.jpg",
> "expirience_points"=>"0", "price"=>"1", "title"=>"w",
> "description"=>"w", "continent_id"=>"7"}, "id"=>"11",
> "controller"=>"products"}
>
> This is the code of may update methode:
> def update
> @product = Product.find(params[:id])
> @product.continent = Continent.find(:first, :conditions => [ "id =
> ?",:continend_id ])
You haven't posted what you're getting as a result, but one problem is
that you don't have a variable named continend_id in your code. You
have a params element named continent_id. Change the Continent.find
clause to use :params[:continent_id]. A couple of other tips.
I always use .to_i on finds where I'm using a param since they're
strings and find takes an integer. It helps to remind me that params
are strings.
Your Continent.find could be shortened to
Continent.find(params[:continent_id].to_i)
HTH,
Bill
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.