我有一个像这样的rails helper文件中的方法
def table_for(collection, *args)
options = args.extract_options!
...
end
Run Code Online (Sandbox Code Playgroud)
我希望能够像这样调用这个方法
args = [:name, :description, :start_date, :end_date]
table_for(@things, args)
Run Code Online (Sandbox Code Playgroud)
这样我就可以根据表单提交动态传入参数.我无法重写该方法,因为我在太多地方使用它,我怎么能这样做?
如何按created_at日期列对ActiveRecord查询返回的数组进行排序?
执行查询后会发生这种情况.
请不要告诉我在查询中执行此操作,因为我需要在视图中执行此操作.
在再次询问之前,我读了" Rubygems,Bundler和RVM之间的关系 ".
好吧,有很多这样的问题,但回答的人说他们使用的是Rubygems,RVM和Bundler,他们没有解释每个问题是如何独立工作的.
当我们安装宝石时,我真的很困惑三者如何孤立地工作.请不要告诉我你的工作方式,这对我有帮助,但是当我们和他们一起玩时,我不会知道发生了什么.
我的困惑可以分解为这些问题.在以下情况下安装宝石的位置:
请通过网络上的资源或您的详细答案帮助我理解这些内容.
在我的rails应用程序中,我正在创建一个这样的数组:
@messages.each do |message|
@list << {
:id => message.id,
:title => message.title,
:time_ago => message.replies.first.created_at
}
end
Run Code Online (Sandbox Code Playgroud)
在制作这个数组之后,我想通过time_ago ASC命令对它进行排序,这可能吗?
从头开始重建mac.安装xcode和rvm然后尝试安装红宝石,但他们都给了我:
Error running ' ./configure --prefix=/Users/durrantm/.rvm/rubies/ruby-1.9.3-p125
--enable-shared --disable-install-doc --with-libyaml
--with-opt-dir=/Users/durrantm/.rvm/usr ',
please read /Users/durrantm/.rvm/log/ruby-1.9.3-p125/configure.log
There has been an error while running configure. Halting the installation.
Michaels-MacBook-Air:~ durrantm$
Run Code Online (Sandbox Code Playgroud)
日志有:
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/Users/durrantm/.rvm/src/ruby-1.9.2-p290':
configure: error: no acceptable C compiler found in $PATH
Run Code Online (Sandbox Code Playgroud)
我需要gcc C compliler吗?我该如何安装?
例如,str = 'abcdefg'.如何c使用Ruby在此字符串中找到索引?
我在安装jekyll时遇到了一些麻烦.无法弄清楚如何修补丢失的链接.我认为这是对Ruby的更新,但RVM也无法安装备用版本的ruby.
下面是完整的帖子:
$ sudo gem install jekyll
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/fast-stemmer-1.0.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/fast-stemmer-1.0.1/ext/gem_make.out
Run Code Online (Sandbox Code Playgroud)
这是否意味着我需要通过rvm更新我正在使用的ruby版本?
例如,我有一些单个哈希值
a = [{a: :b}, {c: :d}]
Run Code Online (Sandbox Code Playgroud)
将它转换成这个的最佳方法是什么?
{a: :b, c: :d}
Run Code Online (Sandbox Code Playgroud) 我正在使用Ubuntu并在使用db:migrate for ruby项目时遇到问题.
rails aborted!
LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile.
/home/juan/odin_on_rails/RailsaAPP/bin/rails:9:in `<top (required)>'
/home/juan/odin_on_rails/RailsaAPP/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
Gem::LoadError: can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile.
/home/juan/odin_on_rails/RailsaAPP/bin/rails:9:in `<top (required)>'
/home/juan/odin_on_rails/RailsaAPP/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate => db:load_config …Run Code Online (Sandbox Code Playgroud)