我已经从网站上抓取产品并将其插入我的数据库。所有的产品都在我的View页面上正确列出,但我似乎无法得到删除按钮的工作。有在我耙路线重复的原因是,我最初写手动路线了,但再使用按钮删除单个数据不起作用。
resources :ibotta
我只是试图移动“资源:ibotta”的路线上,但没有工作。当我点击“消灭”按钮,它需要我的链接是
“https://rails-tutorial2-chriscma.c9users.io/ibotta.14738”
任何帮助非常感谢,谢谢。
查看
<h1>Show Page for iBotta</h1>
<h3><%= @products.length %> products in the iBotta DB</h3>
<% @products.each do |x| %>
<p>Title: <a href=<%=x.link%>><%= x.title %></a> </p>
<p>Value: <%= x.values %> </p>
<p>Store: <%= x.store %> </p>
<%= link_to 'Destroy', ibotta_path(x.id),
method: :delete %>
<% end %>
在控制器方法
def destroy
Ibotta.find(params[:id]).destroy
redirect_to ibotta_path
end
耙路线
ibotta_save GET /ibotta/save(.:format) ibotta#save
ibotta_show GET /ibotta/show(.:format) ibotta#show
ibotta_delete GET /ibotta/delete(.:format) ibotta#delete
ibotta GET /ibotta(.:format) ibotta#index
POST /ibotta(.:format) ibotta#create
new_ibottum GET /ibotta/new(.:format) ibotta#new
edit_ibottum GET /ibotta/:id/edit(.:format) ibotta#edit
ibottum GET /ibotta/:id(.:format) ibotta#show
PATCH /ibotta/:id(.:format) ibotta#update
PUT /ibotta/:id(.:format) ibotta#update
DELETE /ibotta/:id(.:format) ibotta#destroy
我调整了一点这个例子,使它更具表现力,但是你在这里使用了'@products.each do | x |',所以你可以做'<%= link_to'Destroy', x,方法::删除%>。 –