Updating a record error

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 %>

On Tue, Dec 16, 2008 at 5:53 PM, Maulin P.
[email protected] 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. ------------------------ [email protected]