{"id":577,"date":"2022-08-30T15:03:40","date_gmt":"2022-08-30T15:03:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/rails-3-no-method-error-for-attributes-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:40","modified_gmt":"2022-08-30T15:03:40","slug":"rails-3-no-method-error-for-attributes-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/rails-3-no-method-error-for-attributes-collection-of-common-programming-errors\/","title":{"rendered":"Rails 3: No Method Error for Attributes-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m getting the following error message:<\/p>\n<pre><code>NoMethodError in UploadStepsController#update\n\nundefined method `attributes=' for #\n\n\napp\/controllers\/upload_steps_controller.rb:12:in `update'\n<\/code><\/pre>\n<p>I&#8217;m currently building a wizard that allows users to upload files, with the Wicked Wizard gem. What am I missing here?<\/p>\n<p><strong>upload_steps_controller.rb<\/strong><\/p>\n<pre><code>class UploadStepsController &lt; ApplicationController\ninclude Wicked::Wizard\nsteps :audience, :rewards, :review\n\ndef show\n    @upload = current_user.uploads\n    render_wizard\nend\n\ndef update\n    @upload = current_user.uploads\n    @upload.attributes = params[:upload]\n    render_wizard @upload\nend\n\n\nend\n<\/code><\/pre>\n<p><strong>upload.rb<\/strong><\/p>\n<pre><code>class Upload &lt; ActiveRecord::Base\nattr_accessible :title, :tagline, :category, :genre, :length, :description\n\nbelongs_to :user\n\nvalidates :title, presence: true\nvalidates :tagline, presence: true\nvalidates :category, presence: true\nvalidates :genre, presence: true\nvalidates :length, presence: true\nvalidates :description, presence: true\nvalidates :user_id, presence: true\n\ndefault_scope order: 'uploads.created_at DESC'\nend\n<\/code><\/pre>\n<p><strong>new error<\/strong><\/p>\n<pre><code>NoMethodError in UploadStepsController#update\nundefined method `save' for #\n\napp\/controllers\/upload_steps_controller.rb:13:in `update'\n<\/code><\/pre>\n<ol>\n<li>\n<p>current_user.uploads is AREL object. So u have to specify what upload do u want to update. For example first user upload.<\/p>\n<pre><code>current_user.uploads.first.update_attributes(params[:upload])\n<\/code><\/pre>\n<p>or maybe<\/p>\n<pre><code>@upload = current_user.uploads.find(params[:upload].delete(:id))\n@upload.update_attributes(params[:upload])\n<\/code><\/pre>\n<p>or all records<\/p>\n<pre><code>@upload = current_user.uploads\n@upload.update_all(params[:upload])\n<\/code><\/pre>\n<\/li>\n<li>\n<p>try this instead:<\/p>\n<pre><code>@upload.update_attributes(params[:upload])\n<\/code><\/pre>\n<\/li>\n<li>\n<p>@upload = current_user.uploads, it is given you the array of uploads object, but attributes methods is apply for single object. So you have to apply each methods<\/p>\n<pre><code>@uploads = current_user.uploads\n@uploads.each do | upload|\n  upload.update_attributes(params[:upload])\nend\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:04:27. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m getting the following error message: NoMethodError in UploadStepsController#update undefined method `attributes=&#8217; for # app\/controllers\/upload_steps_controller.rb:12:in `update&#8217; I&#8217;m currently building a wizard that allows users to upload files, with the Wicked Wizard gem. What am I missing here? upload_steps_controller.rb class UploadStepsController &lt; ApplicationController include Wicked::Wizard steps :audience, :rewards, :review def show @upload = current_user.uploads render_wizard end [&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-577","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/577","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=577"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/577\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}