button_to :action => 'destroy' looks for 'show'

前端 未结 2 1961
醉梦人生
醉梦人生 2020-12-29 04:39

This seems incredibly similar to a question I had answered just a few days ago, but the solution then isn\'t working now.

I\'m building a rails app, and I am trying

相关标签:
2条回答
  • 2020-12-29 05:12

    And how you part of routes.rb for that one looks like? Because if you use map.resources then destroy has same path as show but :method => :delete(which is virtual verb implemented by form and _method=delete param).

    Try this:

    <%= button_to "delete", {:controller => :meals,
          :action => 'destroy', :id => recipe.id }, :method => :delete %>
    

    or if recipe is instance of Meal class then

    <%= button_to "delete", @recipe, :method => :delete %>
    

    Mind the curly brackets.

    0 讨论(0)
  • 2020-12-29 05:37

    I know it is way too late for an answer but hope it may help somebody(using Rails 4).

     <%= button_to "delete", meal_path(:id => recipe.id), :method => :delete %>
    
    0 讨论(0)
提交回复
热议问题