Reputation: 13771
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:
param is missing or the value is empty: link
The code snippet it is complaining about is:
def link_params
params.require(:link).permit(:description, :link_url)
end
Here is my destroy code:
def destroy
@opportunity = Opportunity.find(params[:opportunity_id])
@link = @opportunity.links.find(link_params)
@link.destroy
respond_to do |format|
format.html { redirect_to links_url, notice: 'Link was successfully destroyed.' }
format.json { head :no_content }
end
Upvotes: 1
Views: 13965
Reputation: 1
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]
Upvotes: 0
Reputation: 5919
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.
Upvotes: 7