删除没有脚手架的动作

时间:2013-07-01 21:49:45

标签: ruby-on-rails ruby-on-rails-4

状态资源(由" 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;列表)。如何将用户重定向到主页,或者更好,在之前的页面上

1 个答案:

答案 0 :(得分:1)

<{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主页返回。