Rails 4.0 param is missing or the value is empty

前端 未结 2 957
夕颜
夕颜 2021-01-16 13:46

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

相关标签:
2条回答
  • 2021-01-16 13:50

    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.

    0 讨论(0)
  • 2021-01-16 13:52

    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]

    0 讨论(0)
提交回复
热议问题