Forum: Ruby on Rails How do I update the mysql db ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
525e0c75f4f5c1d0ab0b6cc91575b74f?d=identicon&s=25 Emil Kampp (emuen)
on 2007-01-15 23:13
Hi there.

I have a forum controller, where the admin can change the status of a
treat, in /forums/status/ID?status=STATUS

in the controller, i have defined it as

def status
  @treatId = params[:id]
  @status = params[:status]

What code should i use to update the status in the row corresponding to
the @treatId ?

Thanks :) Emil
520c24bad2fa9b171d022e3600cd5e58?d=identicon&s=25 Mark Noten (mnoten)
on 2007-01-16 13:06
Hi Emil,

first of all it seems to me like you're using the GET method for
updating the status. I think you better stick to the POST method for
your form. The GET method is good for querying your database through
request parameters. The POST method is better for creating or editing a

So your URL should become with the GET method something like
/forums/status/4. In your controller you can put:

def status
  @thread = Thread.find(params[:thread][:id])
  @thread.update_attributes = params[:thread]

If in your form have update one attribute like the status
(params[:thread][:status]) then the update_attributes will only update
this attribute.

I'm just a newbie to Ruby and these are my suggestions...

Best regards,

This topic is locked and can not be replied to.