# Updating a record error

**URL:** <https://www.ruby-forum.com/t/updating-a-record-error/155806>\
**Category:** Rails\
**Created:** [December 17, 2008, 2:53am UTC](https://www.ruby-forum.com/t/updating-a-record-error/155806 "2008-12-17T02:53:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 17, 2008, 2:53am UTC](https://www.ruby-forum.com/t/updating-a-record-error/155806/1 "2008-12-17T02:53:15Z")

</div>

I have having some trouble with my update statement. I have a page that  
allows users to change their personal information (name,  
password…etc), The update statement seems to execute successfully but  
does not update anything. What am I missing?

## MODEL CODE

class Player \< ActiveRecord::Base  
has\_many :statistics  
has\_many :ladders, :through =\> :statistics

validates\_presence\_of :first\_name, :last\_name, :login, :password  
end

## CONTROLLER CODE

def edit  
@player = Player.find(params[:id])  
end

def update  
Player.update(params[:id],  
{:first\_name =\> params[:first\_name],  
:last\_name =\> params[:last\_name],  
:login =\> params[:login],  
:password =\> params[:password]})  
flash[:notice] = “Personal information updated sucessfully  
#{params[:id]}”  
redirect\_to player\_path(@current\_player)  
end

## VIEW CODE

The edit method is called from another view as follows

\<% form\_tag(edit\_player\_path(@player), :method =\> "get") do %\> \<%= submit\_tag 'Edit personal information' %\> \<% end %\>

## EDIT VIEW

## Edit personal information
\<%= render :partial =\> 'form' %\>
## FORM VIEW

\<%= error\_messages\_for ‘player’ %\>  
\<% form\_for(@player) do |f| %\>

First Name:  
 \<%= f.text\_field :first\_name %\>

Last Name:  
 \<%= f.text\_field :last\_name %\>

Username:  
 \<%= f.text\_field :login %\>

Password:  
 \<%= f.password\_field :password %\>

\<%= submit\_tag "Save" %\>

\<% end %\>

---

<div class="post-metadata">

**Author:** ![mpathare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@mpathare](https://www.ruby-forum.com/u/mpathare)\
**Post date:** [December 17, 2008, 3:56am UTC](https://www.ruby-forum.com/t/updating-a-record-error/155806/2 "2008-12-17T03:56:15Z")

</div>

On Tue, Dec 16, 2008 at 5:53 PM, Maulin P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have having some trouble with my update statement. I have a page that  
> allows users to change their personal information (name,  
> password…etc), The update statement seems to execute successfully but  
> does not update anything. What am I missing?

> def update  
> Player.update(params[:id],  
> {:first\_name =\> params[:first\_name],

Per the api doc, ActiveRecord::Base.update  
“Updates an object (or multiple objects) and saves it to the database,  
if validations pass. The resulting object is returned whether the object  
was saved successfully to the database or not.”

Are you logging validation errors on this? If not, or just for grins,  
you  
might change the controller to Player.update\_attributes! to try to make  
the error visible…

Alternatively, does your DB log show any problems?

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid
