title: Rails 4 how to call accessible_attributes from Model
body: <p>Hi I'm trying this tuto on Rails cast (<a href="http://railscasts.com/episodes/396-importing-csv-and-excel?autoplay=true" rel="nofollow">Importing csv Excel file</a>). And I'm having an error on this line <code>product.attributes = row.to_hash.slice(*accessible_attributes)</code></p>
  
  <p><code>undefined local variable or method</code>accessible_attributes' for #`</p>
  
  <p>this is my model.</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    require 'roo'
    validates_presence_of :price
    #attr_accessible :name, :price, :released_on #I removed this line (rails 4)
  
  
    def self.to_csv(options = {})
      CSV.generate(options) do |csv|
        csv &lt;&lt; column_names
        all.each do |product|
          csv &lt;&lt; product.attributes.values_at(*column_names)
        end
      end
    end
  
    def self.import(file)
      spreadsheet = open_spreadsheet(file)
      header = spreadsheet.row(1)
      (2..spreadsheet.last_row).each do |i|
        row = Hash[[header, spreadsheet.row(i)].transpose]
        product = find_by_id(row["id"]) || new
        product.attributes = row.to_hash.slice(*accessible_attributes)
        product.save!
      end
    end
  
    def self.open_spreadsheet(file)
      case File.extname(file.original_filename)
      when ".csv" then Roo::Csv.new(file.path)
      when ".xls" then Roo::Csv.new(file.path)
      when ".xlsx" then Roo::Csv.new(file.path)
      else raise "Unknown file type: #{file.original_filename}"
      end
    end
  end
  </code></pre>
  
  <p>end on my controller I defined the product_params</p>
  
  <pre><code>def product_params
      params.require(:product).permit(:name, :price, :released_on)
    end
  </code></pre>
  
  <p>my csv that I'm trying to import looks like this:</p>
  
  <pre><code>id,name,realased_on,price,created_at,updated_at
  1,Acoustic Guitar,2012-10-03,3456.54,2013-12-09 00:00:23 UTC, 2012-12-08 23:45:46 UTC
  </code></pre>