国家选择抛出ArgumentError


镜乃Kagamino
2025-03-17 08:39:02 (22天前)
  1. ,英国“,”维尔京群岛,美国“,
  2. “瓦利斯和富图纳群岛”,“西方人


撒哈拉
</跨度>
“,”“也门”,“赞比亚”,“津巴布韦”,除非const_defined?(“国家”)
结束

  1. class InstanceTag
  2. def

5 条回复
  1. 0# Minions | 2019-08-31 10-32



    检查country_select gem的版本。它似乎最近更新为符合Rails 4.x中引入的更改。您需要v1.1.1或更高版本。


  2. 1# Minions | 2019-08-31 10-32



    不幸的是,关于这方面的文档有点稀疏。
    当你的

    country_select

    在一个表格内(即你正在使用

    f.country_select

    …)你不需要提供

    object

    既然你已经拥有了

    form_for(object)




    我在Rails 3.2.17和country_select 1.1.3中成功使用了以下语法:




    1. form_for(myobject) do |f|

      f.country_select country”, [“Australia”, New Zealand”], {}, {class: form-control”, id: country”}

      end

    2. </code>



    “country”

    是的属性

    myobject

    ,澳大利亚和新西兰是优先国家,空洞

    {}

    是选项,其余的是html_options。


  3. 2# 荀彧. | 2019-08-31 10-32



    我必须安装另一个gem来解决Rails版本4.2.0中的相同错误:




    wrong number of arguments(4 for 0)



    宝石被指定为:




    1. gem country_select’, github: stefanpenner/country_select

    2. </code>


    在你的Gemfile中,然后运行

    bundle install

    并重新启动服务器。我找到了这个解决方案

    这里



  4. 3# 诸葛神侯 | 2019-08-31 10-32

    尝试更改视图

    而不是



    1. f.country_select(‘country’)

    2. </code>



    1. country_select(:user, :country)

    2. </code>

登录 后才能参与评论