Using the correct url_for method in a Rails engine spec

天大地大妈咪最大 提交于 2019-11-29 01:28:45
Koichiro Wada

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.

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

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

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]})) %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!