状态资源(由" rails g scaffold Status&#34生成)
resources :statuses
链接销毁对象
<%= link_to "delete", status, :confirm => "are you sure?", :method => :delete%>
layout.html.erb
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
的application.js
//= require jquery
//= require jquery_ujs
Rails 4.0.0
当我点击它时,它会将我重定向到Rails&#39;脚手架页面(状态&#39;列表)。如何将用户重定向到主页,或者更好,在之前的页面上?
答案 0 :(得分:1)
statuses_controller.rb
您应该destroy
行动
def destroy
@status = Status.find(params[:id]) # or find(params[:status_id]) depends on how route is built
@status.destroy
respond_to do |format|
format.html { redirect_to statuses_url }
format.json { head :no_content }
end
end
将redirect_to statuses_url
更改为redirect_to :back
,它会从您的请求开始或redirect_to root_url
主页返回。