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