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 <p> <% form_tag(edit_player_path(@player), :method => "get") do %> <%= submit_tag ''Edit personal information'' %> <% end %> </p> EDIT VIEW ---------- <h2> Edit personal information </h2> <%= render :partial => ''form'' %> FORM VIEW ---------- <%= error_messages_for ''player'' %> <% form_for(@player) do |f| %> <p> First Name:<br> <%= f.text_field :first_name %> </p> <p> Last Name:<br> <%= f.text_field :last_name %> </p> <p> Username:<br> <%= f.text_field :login %> </p> <p> Password:<br> <%= f.password_field :password %> </p> <p> <%= submit_tag "Save" %> </p> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Dec 16, 2008 at 5:53 PM, Maulin Pathare <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---