Reputation: 1
I am new to Ruby on Rails.
I am using Rails 4.0.3, Ruby 1.9.3.
I tried to import CSV file from the sample "396-importing-csv-and-excel-master"
But it is throwing error.
Error:
attr_accessible is no longer in use
and suggests to use Strong parameter. Can any one help me to import CSV using strong parameter?
Upvotes: 0
Views: 587
Reputation: 802
Let's say you are importing Tasks. Use this way for strong parameters
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
task = find_by_id(row["id"]) || new
parameters = ActionController::Parameters.new(row.to_hash)
task.update(parameters.permit(:id,:name))
task.save!
end
end
Upvotes: 1