从命名空间中删除
我已经设置了一个管理命名空间,以便访问管理区域中的模型: /admin/pages
但是我有以下问题 例如,我无法让删除功能在 Admin::PageController
或我的任何模型下工作。
有谁知道该怎么做。 我有以下内容:
Admin::PageController 我有以下内容
def destroy
@page = Page.find(params[:id])
@page.destroy
respond_to do |format|
format.html { redirect_to admin_pages_url }
format.json { head :ok }
end
end
然后在我的页面索引文件上,我想要一个链接来删除记录,我有以下内容: (/admin/pages)
<%=link_to admin_page_path(page), :class => 'ico del' do %>
<%='Delete'%>
<% end %>
似乎不起作用。有人知道如何让它发挥作用吗?
I have setup a admin namespace in order to access models in the admin area: /admin/pages
However i have the following problem
i cant get the delete function to work under Admin::PageController
for example or any of my models.
Does anyone know how to do this.
I have the following:
Admin::PageController I have the following
def destroy
@page = Page.find(params[:id])
@page.destroy
respond_to do |format|
format.html { redirect_to admin_pages_url }
format.json { head :ok }
end
end
Then on my page index file where i want a link to delete the record i have the following: (/admin/pages)
<%=link_to admin_page_path(page), :class => 'ico del' do %>
<%='Delete'%>
<% end %>
Does not seem to work. Anyone know how to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您错过了 link_to 调用中的 :method 选项
或
you have missed :method option in link_to call
or
link_to
帮助程序默认为GET
请求,除非您指定其他属性来告诉它您希望如何处理它。在这种情况下,您需要设置一些额外的参数:
后台实际发生的是 Rails UJS (不显眼的 javascript 适配器)捕获点击事件并通过 AJAX 发送请求。因此,您应该看到它使用
POST
命中您的服务器(但它也传入_method => delete
)来删除该对象。我还假设您的路线设置正确。像这样的东西:
The
link_to
helper defaults to aGET
request unless you specify additional attributes to tell it how you want it to be handled.In this case, you need to set some extra arguments:
What actually happens in the background is the Rails UJS (unobtrusive javascript adapter) captures the click event and sends the request via AJAX. So you should see it hit your server with a
POST
(but it passes in_method => delete
as well) to delete the object.I'm also assuming you have your routes set up correctly. Something like: