Update params only on 1 field

In the controller, the string you are passing in will be available in the params hash, the key being the name of the field in the form. i.e.:

<input type="text" name="my_string"/>

This would be accessible in your controller as params[:my_string]

When you say you want to update only one field, do you mean only one field in the database record, or one field on the form in the page via AJAX?

if you only want to update one field in the database:

@foo = Foo.find(params[:id]) @foo.update_attributes(:my_string => params[:my_string])

or if my_string is the only param in the params hash (other than id) you can just say

@foo.update_attributes(params)

If you only want to update one field on the page via ajax you can use:

render :update do |page|     page[:id_of_field_to_update].replace_html "text to be inserted into element" end

Kevin Ruscoe wrote:

Kevin Ruscoe wrote:

William Pratt wrote:

In the controller, the string you are passing in will be available in the params hash, the key being the name of the field in the form. i.e.:

<input type="text" name="my_string"/>

This would be accessible in your controller as params[:my_string]

Hi,

I want to do the same thing here. But instead of update, I want to save. Is it correct to use the above postings' codings or to do save I need a whole new coding?

Thanks