所以我有这个破坏控制器:
def destroy
Post.find(params[:id]).destroy
flash[:success] = "Post Deleted."
redirect_to users_url
end
这个观点:
<% @posts.each do |i| %>
<li>
This post was created at: <%= i.created_at %></br>
Contents of the post: <%= i.content %>
<%= link_to "Delete this post", @post, method: :delete, class: "black", data: { confirm: "You sure?" } %>
</li>
<% end %>
<% end %>
现在当我进行删除时,它只是将我重定向到我在控制器中创建的页面,就是这样。在服务器日志中,我得到了:
Started DELETE "/users/17" for 127.0.0.1 at 2013-12-16 22:49:31 +0200
Processing by UsersController#destroy as HTML
Parameters: {"authenticity_token"=>"iT08NreZv83WtImK6V9/jXZOpgtzwSLjlxB7T/wn0E4=", "id"=>"17"}
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = '473b76458ca425d9bb927550e7a11eb292393d84' LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :admin_user rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.0ms)
Started GET "/" for 127.0.0.1 at 2013-12-16 22:49:31 +0200
Processing by FormController#home as HTML
Rendered form/home.html.erb within layouts/application (0.0ms)
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = '473b76458ca425d9bb927550e7a11eb292393d84' LIMIT 1
Rendered layouts/_menu.html.erb (2.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 9ms (Views: 9.0ms | ActiveRecord: 0.0ms)
我在这里缺少什么?
答案 0 :(得分:0)
您有一个前置过滤器,用于检查您当前的用户是否为admin_user。您的日志显示您的当前用户不是,因此在您执行destroy操作之前,您将被重定向。
此外,您应该发送带有重定向的Flash消息。 See this post for more info
redirect_to users_url, success: "Post Deleted."