【发布时间】:2014-02-23 16:16:29
【问题描述】:
我对销毁操作有疑问。 它在 index.html.erb 中工作得很好。 但我无法让它在edit.html.erb中工作 即使没有请求许可,它也会路由到节目。
这里的许多解决方案都说它与 jQuery 有关。正如你所看到的,我尝试了所有我能找到的。
<%= stylesheet_link_tag "application" %>
<!--Delete Problem in Edit-->
<%#= javascript_include_tag :all %>
<%#= javascript_include_tag :application %>
<%#= javascript_include_tag :default %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
有适合我情况的解决方案吗?
这是我在编辑中的删除按钮:
<%= content_tag(:a, :href => contact_path(@contact), :class => "btn btn-warning pull-right", :style => "margin:0; margin-right:15px;", confirm: 'Are you sure?', method: :delete) do %>
<%= t "list.button_delete" %>
<%#= link_to I18n.t(".list.delete"), contact, confirm: 'Are you sure?', method: :delete %>
<%#= link_to 'delete', contact_path(@contact), :method => :delete %>
<% end %>
我也尝试了很多东西。
以下是动作:
def destroy
#@contact = Contact.find(params[:id])
@contact = current_user.contacts.find(params[:id])
@contact.destroy
redirect_to contacts_url,
alert: 'Successfully deleted the contact'
end
【问题讨论】:
-
请看我更新的答案。
标签: ruby-on-rails ruby routing edit destroy