希望是一个简单的答案; 我正在使用gem best_in_place,效果很好.我正在尝试使用以下方法找出如何创建下拉菜单:
:type => :select, :collection => []
Run Code Online (Sandbox Code Playgroud)
我想要做的是传递从我的用户模型输入的名称列表.
有什么想法怎么做?我可以将它与collection_select混合使用吗?
我正在尝试从CSV文件将种子数据加载到我的Rails应用程序中.我最初安装了fastercsv gem,但是发现从ruby 1.9开始不推荐使用updatedcsv而支持CSV库.所以我在收到一个非常有用的错误告诉我切换后切换到CSV.
然而,现在,我得到了最奇怪的现象,当我加载我的数据时,一切看起来都很正常,但我似乎无法查询字符串字段.字符串字段由看似正确的字符串填充,但我无法访问它们.我可以查询任何数字字段,结果将返回,但不返回字符串字段.我尝试使用分隔符来报价,但无济于事.我甚至从我的csv文件中删除了所有引号,但仍然无法查询字符串字段.下面是我的代码,以及Rails控制台的一些示例查询和返回.
# seeds.rb
# ================
require 'csv'
directory = "db/init_data/"
file_name = "players.seed"
path_to_file = directory + file_name
puts 'Loading Player records'
# Pre-load All Player records
n=0
CSV.foreach(path_to_file) do |row|
Player.create! :first_name => row[1], :last_name => row[2], :position_id => row[5], :weight => row[6], :height => row[7], :year => row[8], :home_state => row[9], :home_town => row[10], :home_country => row[11], :high_school_id => row[12], :name => row[13]
n=n+1
end
Run Code Online (Sandbox Code Playgroud)
这是我的种子文件中的前两个记录.
# players.seed
"1","Allerik","Freeman","2011-10-11 22:21:21.230247","2011-10-11 22:21:21.230247","2","210","76","2013","NC","Charlotte","USA","1","Allerik Freeman"
"2","Kasey","Hill","2011-10-11 22:21:21.262409","2011-10-11 22:21:21.262409","1","170","73","2013","FL","Eustis","USA","2","Kasey …Run Code Online (Sandbox Code Playgroud) 我正在尝试安装新的rails应用程序.我已经在我的机器上安装了几个rails应用程序,一切正常.
$ rails new app
Could not locate Gemfile
Run Code Online (Sandbox Code Playgroud)
然后,我想我会运行跟踪来找出发生了什么事情,因为你不会期望有一个Gemfile在这一点上,无论如何,因为通常上面的命令将在名为目录中创建一个全新的Rails应用app与Gemfile载在该目录中.
$ rails new app --trace
Could not locate Gemfile
Run Code Online (Sandbox Code Playgroud)
因此,我尝试通过此详细指南重新安装计算机上的所有内容:
http://railsapps.github.com/installing-rails.html#gems
在前20个步骤之后,我得到了这个命令:
$ rake -v
Could not locate Gemfile
Run Code Online (Sandbox Code Playgroud)
我假设某些地方的设置已关闭,但我看不到任何关闭.
这是我的rvm设置:
$ rvm version
rvm 1.18.10 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ rvm list
rvm rubies
jruby-1.6.7 [ x86_64 ]
ruby-1.9.1-p431 [ i386 ]
ruby-1.9.3-p194 [ x86_64 ]
ruby-1.9.3-p286 [ x86_64 ]
ruby-1.9.3-p327 [ x86_64 ]
=* ruby-1.9.3-p385 [ …Run Code Online (Sandbox Code Playgroud)