How do I update the mysql db?

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 :slight_smile: Emil

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,