简体   繁体   English

当我包含“Rails.application.routes.url_helpers”时,参数数量错误(0为0..1)

[英]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.

相关问题 从Rails.application.routes.url_helpers访问引擎路由 - Accessing engine routes from Rails.application.routes.url_helpers include Rails.application.routes.url_helpers导致ArgumentError缺少主机链接到 - include Rails.application.routes.url_helpers cause ArgumentError Missing host to link to Rails.application.routes.url_helpers丢失的方法 - Rails.application.routes.url_helpers missing method 在哪里为Rails.application.routes.url_helpers设置主机 - Where to set host for Rails.application.routes.url_helpers 仅当Rails.application.routes.url_helpers存在路由时,才将链接链接到路径 - Link_to a path only if route exists with Rails.application.routes.url_helpers Rails - 错误的参数数量(2为0..1)错误 - Rails - wrong number of arguments (2 for 0..1) error Rails - Geocoder - 。参数数量错误(给定3,预期0..1) - Rails - Geocoder - .near wrong number of arguments (given 3, expected 0..1) 升级到 Rails 6 后参数数量错误(给定 4,预期为 0..1) - wrong number of arguments (given 4, expected 0..1) after upgrading to Rails 6 Rails:ActionView::Template::Error(参数数量错误(给定 4,预期 0..1)): - Rails: ActionView::Template::Error (wrong number of arguments (given 4, expected 0..1)): 在Rails中导入时,参数数目错误(给定2,应为0..1) - wrong number of arguments (given 2, expected 0..1) while importing in Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM