Rails path-helpers doesn't work in js.coffee.erb

前端 未结 2 1548
清酒与你
清酒与你 2020-12-18 05:36

In my Rails 3.2 app (Ruby 1.9) I get following error when using path helpers in Coffeescript.

undefined local variable or method `new_user_session_path\'
         


        
2条回答
  •  一生所求
    2020-12-18 06:16

    Old post, but still accessible from Google.

    In rails 4 (and certainly at least 3 too) you can use the route helpers to insert your js files easily:

    assets/javascript/my_file.js.coffee.erb

    <% self.class.include Rails.application.routes.url_helpers %>
    window.index_route = '<%= index_path %>'
    

提交回复
热议问题