gpt4 book ai didi

ruby-on-rails - rails : how to use language list gem with select_tag in a form?

转载 作者:行者123 更新时间:2023-12-04 06:27:47 25 4
gpt4 key购买 nike

我正在尝试创建一个表单,其中一个问题是选择一种特定的语言。我在这里尝试使用语言列表 gem:https://github.com/scsmith/language_list .但是,文档并没有真正告诉我如何将列表与 select_tag 结合起来。

<%= form_for users_path, :method => "get" do %>

<%= label_tag "Select Country" %> <br>
<%= country_select(:user, :country, [], :include_blank => true) %> <br>

<%= label_tag "Language spoken" %>
<%= select_tag "Language", options_from_collection_for_select(LanguageList::COMMON_LANGUAGES, "id", "name") %>

<%= label_tag "City" %> <br>
<%= text_field_tag(:city) %>


<% end %>

给我错误

undefined method 'id' for afr (af) - Afrikaans:LanguageList::LanguageInfo

在线

<%= select_tag "Language", options_from_collection_for_select(LanguageList::COMMON_LANGUAGES, "id", "name") %>

谁能帮帮我?

最佳答案

不要使用"id"。文档说你应该使用 iso_639_1(或者如果你想要 3 字母代码则使用 iso_639_3)

<%= select_tag "Language", options_from_collection_for_select(LanguageList::COMMON_LANGUAGES, "iso_639_1", "name") %>

关于ruby-on-rails - rails : how to use language list gem with select_tag in a form?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13464277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com