コントローラ:
class HorsesController < ApplicationController
require 'csv'
def index
@horses = Horse.all
end
def import
Horse.import(params[:file])
redirect_to root_path
end
end
モデル:
class Horse < ActiveRecord::Base
attr_accessible :name, :place
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Horse.create! row.to_hash
end
end
end
データ タイトル名と場所の 2 つの列を含む CSV ファイルがあります。ファイルをインポートしようとすると、次のようなエラーが表示されます。Can't mass-assign protected attributes: place
:nameは問題ないようですが、何らかの理由で:placeでは動作しませんか ???
どんな助けでも大歓迎