Using the correct url_for method in a Rails engine spec

前端 未结 4 1352
自闭症患者
自闭症患者 2020-12-15 21:27

I have a request spec in a Rails engine. The view that is rendered calls a route and passes in a hash, i.e. projects_path(:scope => \"user\"). A route like t

相关标签:
4条回答
  • 2020-12-15 21:40

    I had the same issue when updating to Rails 4, and I discovered that the problem was a model containing the following line:

    include Rails.application.routes.url_helpers
    

    Try finding code in your application that includes url_helpers somewhere. Removing that line should help solve the problem.

    0 讨论(0)
  • 2020-12-15 21:42

    include ActionView::Helpers::UrlHelper -> In my case, this was the line that i had to search and comment.

    0 讨论(0)
  • 2020-12-15 21:47

    It looks to me like the problem is that include ActionView::Helpers and include Rails.application.routes.url_helpers conflict with each other.

    I've found that if you put ActionView::Helpers first it doesn't raise the error. So change

    include Rails.application.routes.url_helpers     
    include ActionView::Helpers
    

    to

    include ActionView::Helpers
    include Rails.application.routes.url_helpers
    
    0 讨论(0)
  • 2020-12-15 22:06

    For me, the issue was caused by passing a hash as the second argument of a link_to line.

    <%= link_to('click me', {one: params[:one], two: params[:two]}) %>
    

    wrapping the hash in the actual path method for the page fixed the issue

    <%= link_to('click me', actual_path({one: params[:one], two: params[:two]})) %>
    
    0 讨论(0)
提交回复
热议问题