{"id":536,"date":"2022-08-30T15:02:59","date_gmt":"2022-08-30T15:02:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/cant-update-user-attributes-rails-and-devise-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:59","modified_gmt":"2022-08-30T15:02:59","slug":"cant-update-user-attributes-rails-and-devise-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cant-update-user-attributes-rails-and-devise-collection-of-common-programming-errors\/","title":{"rendered":"Can&#39;t update user attributes &#8211; Rails and Devise-Collection of common programming errors"},"content":{"rendered":"<p>I am using Rails (3.0.9) with Devise (1.5.3) and I have an User model in which the attributes can&#8217;t be updated for some reason I have no idea about.<\/p>\n<p>The form for this User object has many attributes including those from devise: password and password_confirmation, for example.<\/p>\n<p>When I submit the form I get this in the logger:<\/p>\n<p><code>WARNING: Can't mass-assign protected attributes: current_password<\/code><\/p>\n<p>But when I add <code>current_password<\/code> to <code>attr_accessible<\/code> I get:<\/p>\n<p><code>ActiveRecord::UnknownAttributeError at \/users unknown attribute: current_password<\/code><\/p>\n<p>I am not very into Devise but I think current_password is just a virtual attribute. This error is very annoying, have you any idea on why this is happening? I am clueless.<\/p>\n<p>By the way, my <code>Users::RegistrationsController#update<\/code> action:<\/p>\n<pre><code>def update\n  logger.error \"SALMONELLA \" + self.resource.password.inspect\n\n  self.resource = resource_class.to_adapter.get!(send(:\"current_#{resource_name}\").to_key)\n\n  #params[:user].delete [:current_password]\n\n  if resource.update_attributes(params[:user])\n    Resque.enqueue(MdcUpdateUser, resource.id)\n    set_flash_message :notice, :updated if is_navigational_format?\n    sign_in resource_name, resource, :bypass =&gt; true\n    respond_with resource, :location =&gt; after_update_path_for(resource)\n  else\n    clean_up_passwords(resource)\n    respond_with_navigational(resource){ render_with_scope :edit }\n  end\nend\n<\/code><\/pre>\n<p>I&#8217;ve tried using Devise&#8217;s <code>update_without_password<\/code> and tried also deleting <code>current_password<\/code> from the <code>params[:user]<\/code> hash but had no success.<\/p>\n<p>I appreciate any help you give me. Please ask for any more information if you think there is any information missing in this question.<\/p>\n<ol>\n<li>\n<p>Then you may have to also add <code>attr_accessor :current_password<\/code> to your model. Also see the Devise Wiki and this issue for further insight.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:20:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am using Rails (3.0.9) with Devise (1.5.3) and I have an User model in which the attributes can&#8217;t be updated for some reason I have no idea about. The form for this User object has many attributes including those from devise: password and password_confirmation, for example. When I submit the form I get this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-536","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=536"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/536\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}