假设我有一个消息资源。我在 html 的某处有:
<%= link_to("Delete", message, :title => 'Delete', :confirm => 'Are you sure?',
:method => :delete )%>
在我删除它之后,它立即将我重定向到列出所有消息的页面。有没有办法在删除后重定向到我指定的页面?
最佳答案
在 Controller 中:
def delete
Item.find(params[:id]).destroy
redirect_to :action => "index"
end
要重定向到最后一个 url,请使用:
redirect_to :back
http://api.rubyonrails.org/classes/ActionController/Base.html#M000662
如果您能学会如何阅读 api 文档,一旦您掌握了它们,它们将非常有用。
关于ruby-on-rails - 在 Rails 中进行 RESTful 删除后,是否可以重定向到特定页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1857711/