I have successfully gotten CSV files to be imported following the steps outlined in the Railscast 396 episode. However, now I'm trying to import a csv that is nested. I have seen other posts where people are trying to import both the parent and the child data but in this case I'm trying to only import the child data on the econ_report show view.
For example, I have econ_results that I'm trying to import that is nested under an econ_report. The rake file shows the following link.
import_econ_report_econ_results
When I try to load the show page for the econ_report I get the following error
No route matches {:action=>"import", :controller=>"econ_results", :id=>"1"} missing required keys: [:econ_report_id]
I have the following code in the econ_result.rd file:
def self.to_csv
CSV.generate do |csv|
csv << column_names
all.each do |sub|
csv << sub.attributes.values_at(*column_names)
end
end
end
def self.import(file)
CSV.foreach(file.path,headers: true) do |row|
EconResult.create! row.to_hash
end
end
Lastly, in the econ_results_controller I have the following code:
before_action :set_econ_report
def set_econ_report
@econ_report = EconReport.find(params[:econ_report_id])
end
def import
EconResult.import(params[:file])
end
def create
@econ_result = @econ_report.econ_results.create(econ_result_params)
redirect_to @econ_report
end
Is the designation of @econ_report causing the conflict in the controller?