小编alo*_*z02的帖子

如何从country_select gem中将国家列表提取到数组中

我正在尝试从country_select gem 中提取所有国家/地区名称的列表并将它们放入数组中。在表单中添加选择字段时,如何利用这个 gem 非常清楚:

<%= form_for User.new, url: root_url do |f| %>
  <%= f.country_select :country_code %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

但是如果我需要在表单之外使用相同的国家/地区列表怎么办。就我而言,我使用X-editable-rails gem进行内联编辑。我的目标是使内联版本可用于国家/地区属性。为此,我必须指定选择列表的来源,如下所示:

<%= editable @waiter, :country, type: :select, title: 'Your country', source: ["Country_1", "Country_2", "Country_n"] %>
Run Code Online (Sandbox Code Playgroud)

但是,我无法想出一种方法来提取该列表并将其放入变量中。

我在这个堆栈溢出答案中尝试了这两种建议的方法:

@countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES.zip(ActionView::Helpers::FormOptionsHelper::COUNTRIES)
Run Code Online (Sandbox Code Playgroud)

<%= @countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES %>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助实现这一目标吗?

ruby-on-rails x-editable

3
推荐指数
1
解决办法
953
查看次数

通过 RVM 安装 Ruby 时运行配置时出错“C 编译器无法创建可执行文件”

不管出于什么原因,我刚刚破坏了我的 RVM(它工作得很好)并尝试再次安装它。当 RVM 测试编译器时,我遇到了阻止安装的错误。我将不胜感激任何调试此问题的帮助。

运行后出现问题:

$ rvm install 2.6.2
Run Code Online (Sandbox Code Playgroud)

任何其他版本的 Ruby。

我得到以下输出

Error running './configure --prefix=/Users/andres/.rvm/rubies/ruby-

2.6.2  --with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/readline:/usr/local/opt/libksba:/usr/local/opt/openssl@1.1 --disable-install-doc --enable-shared',
    please read /Users/andres/.rvm/log/1554329766_ruby-2.6.2/configure.log
    There has been an error while running configure. Halting the installation.
Run Code Online (Sandbox Code Playgroud)

配置日志显示

[2019-04-04 09:07:04] ./configure
current path: /Users/andres/.rvm/src/ruby-2.6.0
PATH=/usr/local/opt/coreutils/bin:/usr/local/opt/pkg-config/bin:/usr/local/opt/libtool/bin:/usr/local/opt/automake/bin:/usr/local/opt/autoconf/bin:/usr/local/opt/node@8/bin:/usr/local/opt/node@8/bin:/opt/local/bin:/opt/local/sbin:/Users/andres/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/node@8/bin:/opt/local/bin:/opt/local/sbin:/Users/andres/bin:/Users/andres/.rvm/bin
command(5): ./configure --prefix=/Users/andres/.rvm/rubies/ruby-2.6.0 --with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/readline:/usr/local/opt/libksba:/usr/local/opt/openssl@1.1 --disable-install-doc --enable-shared
checking for ruby... /usr/bin/ruby
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-apple-darwin18.5.0
checking host system type... x86_64-apple-darwin18.5.0
checking target system type... x86_64-apple-darwin18.5.0
checking whether the C compiler works... no …
Run Code Online (Sandbox Code Playgroud)

ruby macos rvm

3
推荐指数
1
解决办法
6412
查看次数

如何在尝试使用 RVM 安装 Rails 时修复错误

我正在尝试使用最新版本的 Ruby 安装带有 RVM 的 Rails,但在安装 Nokogiri 时遇到问题。

我已经有一些使用 Ruby 2.4.0 的 RVM gemset,我没有遇到任何问题。我安装了 Ruby 2.4.1:

rvm install ruby-2.4.0
Run Code Online (Sandbox Code Playgroud)

并创建了一个新的 gemset:

rvm use ruby-2.4.1@quiniela --create
Run Code Online (Sandbox Code Playgroud)

然后跑:

gem install rails --pre
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    current directory: /Users/andres/.rvm/gems/ruby-2.4.1@quiniela/gems/nokogiri-1.7.1/ext/nokogiri
/Users/andres/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170325-50295-1sw75cw.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for iconv.h... yes
checking for …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails nokogiri rvm

1
推荐指数
1
解决办法
721
查看次数

标签 统计

ruby ×2

ruby-on-rails ×2

rvm ×2

macos ×1

nokogiri ×1

x-editable ×1