Updating only one column in a table

hi all,

       im having a table called employees in db.the table hava five

columns as

1.username
2.password
3.firstname
4.lastname
5.mailid.

      in this i want to update only password column.how to do

it.people knows it please help me.

On 8 Apr 2008, at 10:06, Karthikragunath B. wrote:

3.firstname
4.lastname
5.mailid.

     in this i want to update only password column.how to do

it.people knows it please help me.

ActiveRecord does have an update_attribute method, however (despite
the name) it saves the whole record. You can probably force it to save
less if you had loaded the record with a more restrictive :select. Or
you can drop down a level and use Employee.update_all

Fred

It’s also worth nothing that the next release of Rails (2.1) will do
just the kind of save you’re asking about. If this is not an
immediate production demand it may be worth coding with the standard
methods in the short term and absorb the penalty hit and getting the
functionality for free when 2.1 is released.

On Apr 8, 5:20 am, Frederick C. [email protected]

u can do update like
Employee.update_attributes(:password => params[:employee][:password])

:slight_smile:

On Tue, Apr 8, 2008 at 2:50 PM, Frederick C.
[email protected]

Karthikragunath B. wrote:

hi all,

       im having a table called employees in db.the table hava five

columns as

1.username
2.password
3.firstname
4.lastname
5.mailid.

      in this i want to update only password column.how to do

it.people knows it please help me.

If nothing else helps, you can do this,

Employee.connection.execute(“update employees set
password=‘superseekret’ where id=123”)

(Look up some means to prevent SQL-Injection.)

Stephan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs