相关疑难解决方法(0)

Rails 4 link_to Destroy在"入门"教程中不起作用

我正在通过入门教程(创建一个博客)和link_to Destroy无法正常运行.在终端中,它总是将其解释为#SHOW.

在阅读类似问题时,我了解到删除必须转换为POST以供浏览器解释.这似乎没有发生.

我也在Lynda.com Rails课程中使用Destroy遇到了同样的问题,所以它让我相信它是我开发环境中的东西.我在MacBook Pro Lion上使用Rails 4,Ruby 2.00p274,MySQL,WEBrick作为HTTP服务器.

在选择Destroy时的终端会话中:

Started GET "/posts/4" for 127.0.0.1 at 2013-08-09 13:45:20 -0600
Processing by PostsController#show as HTML
  Parameters: {"id"=>"4"}
  Post Load (0.6ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1  [["id", "4"]]
  Rendered posts/show.html.erb within layouts/application (0.4ms)
Completed 200 OK in 13ms (Views: 8.6ms | ActiveRecord: 0.6ms)
Run Code Online (Sandbox Code Playgroud)

在ports-controller.rb中:

def destroy
    @post = Post.find(params[:id])
    @post.destroy

    redirect_to action: :index
end
Run Code Online (Sandbox Code Playgroud)

在index.html.erb中:

<% @posts.each do |post| %>
  <tr>
    <td><%= post.title %></td>
     <td><%= post.text %></td> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

40
推荐指数
5
解决办法
6万
查看次数

标签 统计

ruby-on-rails ×1