代码之家  ›  专栏  ›  技术社区  ›  Jamis Charles

删除链接在Rails 3视图中发送“get”而不是“delete”

  •  39
  • Jamis Charles  · 技术社区  · 15 年前

    我使用的是Rails3,有一个页面可以从数据库输出文章列表。我想从链接中删除一篇文章。

    下面的第二个例子是可行的,但第一个却不行。有人知道第一个为什么行不通吗?我的视图包含:

    # this link sends a "GET" request which asks for the #show function  
    <%= link_to 'Delete', post, :method => :delete %>
    
    # this link sends the proper "DELETE" request which asks for the #destroy function
    <%= button_to 'Delete', post, :method => :delete %>
    

    我的路由文件包含以下内容:

    resources :posts 
    
    8 回复  |  直到 7 年前
        1
  •  48
  •   vonconrad    15 年前

    <head>

    <%= javascript_include_tag :defaults %>
    <%= csrf_meta_tag %>
    

    :defaults

    here

    button_to

        2
  •  17
  •   alikk    12 年前

    <%= javascript_include_tag :defaults %>
    

    http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers/javascript_include_tag

    <%= javascript_include_tag 'application' %>
    
        3
  •  3
  •   Ninad    15 年前

    <%= javascript_include_tag :defaults %>
    <%= csrf_meta_tag %>
    

        5
  •  2
  •   Romalex    7 年前

    <%= javascript_include_tag "rails-ujs" %>
    

    Rails.application.config.assets.precompile += %w( rails-ujs.js )
    
        6
  •  0
  •   FlyingV    10 年前

    <%= link_to 'Delete', post_path(post.id), :method => :delete %>
    
        7
  •  0
  •   matiasmasca    7 年前

    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    

    ... </title>
      <%= csrf_meta_tags %>
      <%= csp_meta_tag %>
    ...
     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
     </head>
    
        8
  •  -1
  •   lordzeus1989    10 年前