Rails 3: No Method Error for Attributes-Collection of common programming errors

I’m getting the following error message:

NoMethodError in UploadStepsController#update

undefined method `attributes=' for #


app/controllers/upload_steps_controller.rb:12:in `update'

I’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 < ApplicationController
include Wicked::Wizard
steps :audience, :rewards, :review

def show
    @upload = current_user.uploads
    render_wizard
end

def update
    @upload = current_user.uploads
    @upload.attributes = params[:upload]
    render_wizard @upload
end


end

upload.rb

class Upload < ActiveRecord::Base
attr_accessible :title, :tagline, :category, :genre, :length, :description

belongs_to :user

validates :title, presence: true
validates :tagline, presence: true
validates :category, presence: true
validates :genre, presence: true
validates :length, presence: true
validates :description, presence: true
validates :user_id, presence: true

default_scope order: 'uploads.created_at DESC'
end

new error

NoMethodError in UploadStepsController#update
undefined method `save' for #

app/controllers/upload_steps_controller.rb:13:in `update'
  1. current_user.uploads is AREL object. So u have to specify what upload do u want to update. For example first user upload.

    current_user.uploads.first.update_attributes(params[:upload])
    

    or maybe

    @upload = current_user.uploads.find(params[:upload].delete(:id))
    @upload.update_attributes(params[:upload])
    

    or all records

    @upload = current_user.uploads
    @upload.update_all(params[:upload])
    
  2. try this instead:

    @upload.update_attributes(params[:upload])
    
  3. @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

    @uploads = current_user.uploads
    @uploads.each do | upload|
      upload.update_attributes(params[:upload])
    end
    

Originally posted 2013-11-09 21:04:27.