I have an Opportunity model that has a nested resource Link. In my views/opportunities/show page when I click on \"DestroY\' for one of the links, I get the error:
p
Change this:
@link = @opportunity.links.find(link_params)
To this:
@link = @opportunity.links.find(params[:id])
You don't have a link
in your params, you just have an id
and an opportunity_id
.
Also, you have this:
respond_to do |format|
format.html { redirect_to links_url, notice: 'Link was successfully destroyed.' }
...
end
I'm guessing you have your links
resource nested inside opportunities
. So there is no links_url
. You need to use, i.e., opportunities_links_url(@opportunity)
.
Finally, note that you probably want opportunities_links_path
rather than opportunities_links_url
unless you explicitly need absolute URLs in this instance.
You can discover your link helper by running rake routes
. Everything in the leftmost "prefix" column can be called with _url
or _path
on the end to generate a url.
I had the same error. U must be using before_action :link_params at the top, instead do this before_action :link_params,only: [:create]