hi when i want to update a user i have this error: ArgumentError in UsersController#update Unknown key(s): encrypted_password, username, sign_in_count, email Rails.root: /home/delmed/servadmin Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:24:in `update'' lib/chrome_frame.rb:39:in `call'' Request Parameters: {"commit"=>"Modifier ce User", "authenticity_token"=>"Z3PXWLIzHcu5nLm06ntenZA+yj8plf3kXrXQ17bjm2E=", "_method"=>"put", "utf8"=>"✓", "id"=>"1", "user"=>{"encrypted_password"=>"[FILTERED]", "username"=>"user1", "sign_in_count"=>"1", "email"=>"user1-NMfGBQJywjlWk0Htik3J/w@public.gmane.org"}} in all these parametre are in the db in users table. in the controller i have: def edit @user = User.find(params[:id]) render :layout => ''test'' end def update @user = User.find(params[:user]) if @user.update_attributes(params[:user]) falsh[:notice] = ''User was successfully updated.'' else falsh[:notice] = ''Problem update.'' end redirect_to :action => ''index'', :controller => ''user_admins'' end and in the view: <%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :username %><br /> <%= f.text_field :username %><br /> <%= f.label :pwd %><br /> <%= f.text_field :encrypted_password %><br /> <%= f.label :email %><br /> <%= f.text_field :email %><br /> <%= f.label :sign_in_count %><br /> <%= f.text_field :sign_in_count %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> please can you help me!? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 June 2011 19:32, Adel Mediouni <mediouni.adel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi > when i want to update a user i have this error: > > ArgumentError in UsersController#update > > Unknown key(s): encrypted_password, username, sign_in_count, email > > Rails.root: /home/delmed/servadmin > > Application Trace | Framework Trace | Full Trace > app/controllers/users_controller.rb:24:in `update'' > lib/chrome_frame.rb:39:in `call'' > Request > > Parameters: > > {"commit"=>"Modifier ce User", > "authenticity_token"=>"Z3PXWLIzHcu5nLm06ntenZA+yj8plf3kXrXQ17bjm2E=", > "_method"=>"put", > "utf8"=>"✓", > "id"=>"1", > "user"=>{"encrypted_password"=>"[FILTERED]", > "username"=>"user1", > "sign_in_count"=>"1", > "email"=>"user1-NMfGBQJywjlWk0Htik3J/w@public.gmane.org"}} > > in all these parametre are in the db in users table. > in the controller i have: > def edit > @user = User.find(params[:id]) > render :layout => ''test'' > end > def update > > @user = User.find(params[:user]) > if @user.update_attributes(params[:user]) > falsh[:notice] = ''User was successfully updated.''Not part of this problem but it should be flash not falsh> > else > falsh[:notice] = ''Problem update.''Same again> end > ...Can you post the section of db/schema.rb that shows the users table. Also post user.rb (cut out any methods that are not relevant here, if there are any) Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think the issue is here> def update > > @user = User.find(params[:user])^ if you make it def update @user = User.find(params[:id]) ^ Does that fix it? Basically I think the way you have it now has two issues A) is trying to find the user based on the new attributes before they''ve been updated in the db B) more importantly, treating the user''s attributes like options sent to the ''find'' method. I think you can do this but you would have to specify User.find(:all, params[:user]) or User.all(params[:user]) Hope that helps, David -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.