[英]wrong number of arguments (3 for 0..1) when i include “Rails.application.routes.url_helpers”
I have written application_helper.rb, which is basically global helpers for my Rails application. 我编写了application_helper.rb,它基本上是我的Rails应用程序的全局帮助器。 And in order for me to use url helper like
post_url(post)
, Rails force me to include this code at the top of my application_helper.rb: 为了让我像
post_url(post)
一样使用url helper,Rails强迫我将这段代码包含在application_helper.rb的顶部:
include Rails.application.routes.url_helpers
I included that line of code like this: 我包括这样的代码行:
include Rails.application.routes.url_helpers
include ActionView::Helpers::TextHelper
module ApplicationHelper
....
end
And suddenly, when i load my app in the browser, all the link_to
codes seem to be throwing the same kind of error like this: 突然,当我在浏览器中加载我的应用程序时,所有
link_to
代码似乎都抛出了同样的错误,如下所示:
wrong number of arguments (3 for 0..1)
Here is the screenshot of that error: 以下是该错误的屏幕截图:
This is the sample of one my link_to
code: 这是我的一个
link_to
代码的示例:
<%= link_to root_path do %>
<img src="https://googledrive.com/host/xxx/xxx-logo-small.png" class="" />
<% end %>
And its not only this link that is causing an error, but all links in my app! 它不仅是导致错误的链接,而且是我应用中的所有链接! So whats wrong with this
include Rails.application.routes.url_helpers
? 所以这
include Rails.application.routes.url_helpers
什么不对, include Rails.application.routes.url_helpers
? Why is this causing such error? 为什么这会导致这样的错误? And how could I use this and fix the problem it's causing at the same time?
我怎么能用它来解决它同时造成的问题呢?
Thanks! 谢谢!
Do you need add also this includes in your helpers 你是否需要添加这包括你的助手
include AbstractController::Rendering
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include Rails.application.routes.url_helpers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.