Rails 4 link_to Destroy not working in Getting Started tutorial

前端 未结 13 1044
野性不改
野性不改 2020-11-27 04:48

I am working through the Getting Started tutorial (creating a Blog) and the link_to Destroy is not functioning properly. In the terminal it always interprets it as #SHOW. <

相关标签:
13条回答
  • 2020-11-27 05:22

    include below line in js

    //= require jquery_ujs
    

    include gem:

    gem 'jquery-rails'
    

    Destroy Link:

    <%= link_to "Logout", destroy_user_session_path %>
    
    0 讨论(0)
  • 2020-11-27 05:23

    I had the same problem as Barry. Make sure you're copy/pasting correctly in your /app/views/index.html.erb file and inspect the html that is rendered.

    0 讨论(0)
  • 2020-11-27 05:25

    I had the same issue, for rails 4.2.X. Checked all my javascript files but could not make it work. if u look closely at the server request u will be missing 'authenticity_token' in the params, so user gets logged out. In rails 4.1 and above u have to use button_to instead of link_to

    0 讨论(0)
  • 2020-11-27 05:27

    Started GET "/posts/4" for 127.0.0.1 at 2013-08-09 13:45:20 -0600

    This is the problem. The delete link is using GET http verb even though you used method: delete in your link.

    Check out the following SO thread

    0 讨论(0)
  • 2020-11-27 05:31

    Try this

    <%= link_to 'Destroy',  post,  method: :delete, data: { confirm: 'Are you sure?' } %>
    
    0 讨论(0)
  • 2020-11-27 05:38

    I had same problem. In my case, a i had change \app\views\layouts\application.html.erb file from

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    

    to

    <%= stylesheet_link_tag    'default', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
    

    to avoid my very first Rails problem. But it apparently mangled JavaScript execution and caused Destroy issue. Therefore rollback your \app\views\layouts\application.html.erb file to its original state, and treat this problem as here

    Rails ExecJS::ProgramError in Pages#home?

    in evedovelli answer (about coffeescript gem in windows).

    0 讨论(0)
提交回复
热议问题