Rails 4.0 param is missing or the value is empty

感情迁移 提交于 2019-12-01 12:09:28

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]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!