我正在使用带有 Wicegrid 的 Rails 4,我希望在网格的每一行上都有一个链接以便能够删除记录,我已经创建了 link_to,但是当我按下它时出现错误:没有路由匹配 [DELETE]" /”。
我不想将用户发送到删除视图,我想删除记录并刷新网格并留在网格中。
我的控制器看起来像:
def destroy
@risk = current_user.risks.find(params[:id])
@risk.destroy
respond_to do |format|
format.html { redirect_to risks_url }
format.json { head :no_content }
end
end
我的索引视图如下所示:
<%=
grid(@risks_grid) do |g|
g.column name: 'Id', attribute: 'id'
g.column name: 'Title', attribute: 'title' do |p|
p.title if p.title
end
.
g.column do |p|
link_to("Delete", :back, :data => { :confirm => "Are you sure?" }, :action => :destroy, :id => p.id, :method => :delete, :class => 'button-xs')
end
end
%>
谢谢,莱昂