country_select gem throws "NoMethodError", undefined method `country_select' for #

country_select gem throws "NoMethodError", undefined method `country_select' for #

我是 rails 的新手,但我想我正在按照每个步骤使用此 gem。 但是,我收到了 NoMethodError。 我的步骤: 我在终端中 运行 gem install country_select -v 3.1.1。 我停止了我的服务器,运行 捆绑安装,重新启动了我的服务器。 我将该方法添加到我的代码中。我尝试将它添加到我的 gem 文件中,但这导致了一个不同的错误,阻止了我的 Rails 服务器 运行ning(详见下文)。根据 github doc.

,似乎通过终端安装就足够了

唯一一个和我有同样问题的Whosebug问题说是通过重启服务器解决的,但是我试了好几次都没有用。如果有人能在这里帮助我,我将不胜感激!

注意:由于我原来的问题已经得到解答并且问题有所发展,我在这里发布了一个关于终端问题的新问题:

_form.html.erb

 <%= form_with(model: [ @contact, @contact.addresses.build ] ) do |form| %>
  <p>
    <%= form.label :street %><br>
    <%= form.text_field :street %>
  </p>
  <p>
    <%= form.label :town %><br>
    <%= form.text_field :town %>
  </p>
  <p>
    <%= form.label :zip %><br>
    <%= form.text_field :zip %>
  </p>
  <p>
    <%= form.label :state %><br>
    <%= form.text_field :state %>
  </p>
  <p>
    <%= form.label :country %><br>
    <%= form.country_select :country %>
  </p>
  <p>
    <%= form.submit %>
  </p>
<% end %>

show.html.erb

<p>
  <strong>Contact:</strong>
  <p>
  <%= @contact.salutation %>
  <%= @contact.first_name %>
  <%= @contact.middle_name %>
  <%= @contact.last_name %>
  </p>
  <p>
  <strong>SSN:</strong>
  <%= @contact.ssn %><br>
  <strong>Date of Birth:</strong>
  <%= @contact.dob %><br>
  <strong>Comment:</strong>
  <%= @contact.comment %>
  </p>
</p>

<h2>Addresses</h2>
<%= render @contact.addresses %>

<h2>Add an address:</h2>
<%= render 'addresses/form' %>

<%= link_to 'Edit', edit_contact_path(@contact) %> |
<%= link_to 'Back', contacts_path %>

这是来自终端的完整错误:

Completed 500 Internal Server Error in 307ms (ActiveRecord: 67.6ms | Allocations: 85354)


  
ActionView::Template::Error (undefined method `country_select' for #<ActionView::Helpers::FormBuilder:0x00007fd0dcc18428>):
    17:   </p>
    18:   <p>
    19:     <%= form.label :country %><br>
    20:     <%= form.country_select :country %>
    21:   </p>
    22:   <p>
    23:     <%= form.submit %>
  
app/views/addresses/_form.html.erb:20
app/views/addresses/_form.html.erb:1
app/views/contacts/show.html.erb:23

当我将 gem 添加到我的 gem 文件并安装 运行 捆绑包时,我无法重新启动服务器,因为出现此错误:

Could not find i18n_data-0.10.0 in any of the sources
Run `bundle install` to install missing gems.

捆绑安装 returns 以下内容:

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Using rake 13.0.1
Using concurrent-ruby 1.1.7
Using i18n 1.8.5
Using minitest 5.14.2
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using zeitwerk 2.4.0
Using activesupport 6.0.3.3
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.10
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.7.0
Using rails-html-sanitizer 1.3.0
Using actionview 6.0.3.3
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 6.0.3.3
Using nio4r 2.5.3
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 6.0.3.3
Using globalid 0.4.2
Using activejob 6.0.3.3
Using activemodel 6.0.3.3
Using activerecord 6.0.3.3
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 6.0.3.3
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailbox 6.0.3.3
Using actionmailer 6.0.3.3
Using actiontext 6.0.3.3
Using public_suffix 4.0.6
Using addressable 2.7.0
Using bindex 0.8.1
Using msgpack 1.3.3
Using bootsnap 1.4.8
Using bundler 2.1.4
Using byebug 11.1.3
Using regexp_parser 1.7.1
Using xpath 3.2.0
Using capybara 3.33.0
Using childprocess 3.0.0
Using i18n_data 0.10.0
Using sixarm_ruby_unaccent 1.2.0
Using unicode_utils 1.4.0
Using countries 3.0.1
Using sort_alphabetical 1.1.0
Using country_select 4.0.0
Using ffi 1.13.1
Using jbuilder 2.10.1
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using listen 3.2.1
Using method_source 1.0.0
Using pg 1.2.3
Using puma 4.3.6
Using rack-proxy 0.6.5
Using thor 1.0.1
Using railties 6.0.3.3
Using sprockets 4.0.2
Using sprockets-rails 3.2.2
Using rails 6.0.3.3
Using rubyzip 2.3.0
Using sassc 2.4.0
Using tilt 2.0.10
Using sassc-rails 2.1.2
Using sass-rails 6.0.0
Using selenium-webdriver 3.142.7
Using spring 2.1.1
Using spring-watcher-listen 2.0.1
Using turbolinks-source 5.2.0
Using turbolinks 5.2.1
Using web-console 4.0.4
Using webdrivers 4.4.1
Using webpacker 4.3.0
Bundle complete! 18 Gemfile dependencies, 80 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

gem install 在您的计算机上安装 gem。如果您想在 rails 应用程序中包含 gem,则需要将其添加到 gem 文件:

gem 'country_select', '~> 4.0'

我同意,大多数文档在这个意义上都有点模棱两可,但它们是通用的,因为它们无法预见用户打算用 gem.

做什么