首页 > 解决方案 > country_select gem 错误的参数数量错误

问题描述

我把它放在我的gemfile中

gem 'country_select'

我运行捆绑安装

我把它放在我的表格中

= f.country_select(:country, priority_countries: ["US"])

然后,当我重新启动服务器并加载页面时,出现以下错误:

ActionView::Template::Error (wrong number of arguments (given 1, expected 0)):

导轨 5.2

这是整个表格:

= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|

    .row
      .col.s12      
        = devise_error_messages!

    .row
      .input-field.col.s12
        = f.text_field :city
        = f.label :city

    .row
      .input-field.col.s12
        = f.label :country  
        %br
        = f.country_select(:country, priority_countries: ["US"])

这是错误:

ActionView::Template::Error (wrong number of arguments (given 1, expected 0)):
    20:           .input-field.col.s12
    21:             = f.label :country
    22:             %br
    23:             = f.country_select(:country, priority_countries: ["US"])

标签: ruby-on-railsruby-on-rails-5

解决方案


嗨根据用户文档

因为您使用的是设计我假设您在您的用户模型上使用它,所以您必须调用country_select("user", "country", priority_countries: ["US"])

如果您的设计模型被称为其他名称,请将 user 替换为模型名称


推荐阅读