Rails删除前一段时间:id

时间:2015-03-20 23:15:50

标签: ruby routes period

我正在制作一个简单的卡路里计数器,使用http://guides.rubyonrails.org/getting_started.html作为参考。我正在尝试添加删除按钮,但每次尝试运行它时,都会出现错误:
No route matches [DELETE] "/calorieinput.1"

我知道问题是有一段时间而不是斜线,这在这款应用中很常见。我之前在form_for修复了它,但没有一个用于DELETE。我会尝试添加所需的一切,我是新来的,所以如果我忘了什么,我会提前抱歉。

def destroy
  @calinput = Calorie.find(params[:id])
  @calinput.destroy

  redirect_to calorieinput_index_path
end

Prefix Verb URI Pattern Controller#Action calorieinput_index GET /calorieinput(.:format) calorieinput#index POST /calorieinput(.:format) calorieinput#create new_calorieinput GET /calorieinput/new(.:format) calorieinput#new edit_calorieinput GET /calorieinput/:id/edit(.:format) calorieinput#edit calorieinput GET /calorieinput/:id(.:format) calorieinput#show PATCH /calorieinput/:id(.:format) calorieinput#update PUT /calorieinput/:id(.:format) calorieinput#update DELETE /calorieinput/:id(.:format) calorieinput#destroy root GET / welcome#index

<% @calinput.each do |calorieinputs| %>
  <tr>
    <td><%= calorieinputs.food %></td>
    <td><%= calorieinputs.calories %></td>
    <td><%= link_to 'View', calorieinput_path(calorieinputs) %></td>
    <td><%= link_to 'Edit', edit_calorieinput_path(calorieinputs) %></td>
    <td><%= link_to 'Delete', calorieinput_index_path(calorieinputs),
            method: :delete,
            data: { confirm: 'Are you sure you want to delete this post?' } %></td>
  </tr>
<% end %>

感谢任何反馈。

1 个答案:

答案 0 :(得分:0)

我意识到问题是我的DELETE链接中的错误路径。我正在引用索引而不是显示路线。抱歉浪费你的时间。