In my application I created a Job, and on the Job show page I am trying to add the link for creating a Company to be added to that Job:
Company belongs_to Job
In my Job show.html.erb file I have:
<%= link_to "Add Company", new_company_path(:job_id=>@job.id) %>
But, in my Companies controller under new, I have:
@job = params[:job_id]
which returns nill. A check of the params
hash shows that my :job_id=>@job.id
value is not getting added.
Am I doing something wrong? Or is there some thing with the strong parameters in Rails that I need to edit in order to allow my value to go from the Job show page to the Company controller?
Try this:
on view
<%= link_to "Add Company", new_company_path(job_id: @job.id) %>
on controller
@job = params[:job_id]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.