如何通过包含星期几名称的varchar列来订购mysql结果?
请注意,星期一应该先行,而不是星期日.
如何在rails上的ruby中的test.log和development.log上设置自动清理?
是否有设置在服务器启动和测试运行时自动删除开发和测试日志?
我试图为ActiveRecord模型提供一组非常通用的命名范围,如下所示:
module Scopes
def self.included(base)
base.class_eval do
named_scope :not_older_than, lambda {|interval|
{:conditions => ["#{table_name}.created_at >= ?", interval.ago]
}
end
end
end
ActiveRecord::Base.send(:include, Scopes)
class User < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
如果命名范围应该是通用的,我们需要指定*table_name*以防止命名问题(如果它们是来自其他链式命名范围的连接).
问题是我们无法获取table_name,因为它在ActiveRecord :: Base上调用,而不是在User上调用.
User.not_older_than(1.week)
NoMethodError: undefined method `abstract_class?' for Object:Class
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2207:in `class_of_active_record_descendant'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1462:in `base_class'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1138:in `reset_table_name'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1134:in `table_name'
from /home/bogdan/makabu/railsware/startwire/repository/lib/core_ext/active_record/base.rb:15:in `included'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:92:in `call'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:92:in `named_scope'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:97:in `call'
from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:97:in `not_older_than'
Run Code Online (Sandbox Code Playgroud)
如何在Scopes模块中获取实际的table_name?
给出以下两段代码:
def hello(z)
"hello".gsub(/(o)/, &z)
end
z = proc {|m| p $1}
hello(z)
# prints: nil
Run Code Online (Sandbox Code Playgroud)
def hello
z = proc {|m| p $1}
"hello".gsub(/(o)/, &z)
end
hello
# prints: "o"
Run Code Online (Sandbox Code Playgroud)
为什么这两段代码的输出不同?有没有一种方法,以块传递到gsub从方法定义之外,这样的变量$1,$2将被以同样的方式,就好像块的方法定义中给出的评价?
在查看ActiveSupport源代码时,我注意到有时eval会在define_method足够的地方使用.
示例:ActiveSupport:Module.delegate
我认为define_method更干净,更安全的做事方式.是什么带来的好处eval了define_method?性能,内存使用,还有其他什么?
如何在PostgreSQL中按随机天数更改日期?
不幸的是, 生成1到10范围内的随机数 ,截断不起作用:
select date(now()) + (trunc(random() * 20))
Run Code Online (Sandbox Code Playgroud)
结果是:
ERROR: operator does not exist: date + double precision
LÍNEA 1: select date(now()) + (trunc(random() * 20))
Run Code Online (Sandbox Code Playgroud) 我需要收集有关现有ORM解决方案的一些信息.请随时写下任何编程语言.
你能说出你曾经使用过的最好的ORM框架吗?为什么它比其他框架更好?
我们在服务器端遇到libxml-ruby gem问题可能因为它使用了x86_64架构:
$ uname -a Linux ip-10-228-171-64 2.6.21.7-2.fc8xen-ec2-v1.0#1 SMP Tue Sep 1 10:25:30 EDT 2009 x86_64 GNU/Linux
require 'libxml'
LoadError: /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.4/lib/libxml_ruby.so: invalid ELF header - /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.4/lib/libxml_ruby.so
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.4/lib/libxml_ruby.so
from /usr/local/ruby-enterprise/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.4/lib/libxml.rb:9
from /usr/local/ruby-enterprise/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/ruby-enterprise/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /usr/local/ruby-enterprise/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
from (irb):1
Run Code Online (Sandbox Code Playgroud)
宝石版1.1.4
重新安装宝石没有帮助可以有人建议做什么?
我遇到了从solr索引中去除标点符号的问题当标点符号紧跟在一个单词后面时,这个单词没有正确编入索引.
例如:如果我们索引"hello,John",则不会通过关键字"hello"找到资产,而如果我们在单词"hello"之后删除逗号则不会出现问题.
是否有任何FilterFactory假设剥离标点符号?有任何想法吗?
谢谢,波格丹.
如果我的当前目录是 git 项目的子目录并且我调用git pull它总是显示相对于项目根目录的路径。有没有办法查看相对于当前目录的已更改文件路径?
前任。
<root>/default $ git pull
...
Updating 03e5eb12..95987ffb
Fast-forward
../client/styles/components/manageEscrow.styles.ts | 11 +++++
./lib/index.ts | 8 ++--
INSTEAD OF
client/styles/components/manageEscrow.styles.ts | 11 +++++
default/lib/index.ts | 8 ++--
Run Code Online (Sandbox Code Playgroud) ruby ×4
sql ×2
activerecord ×1
comparison ×1
date ×1
dayofweek ×1
elf ×1
eval ×1
frameworks ×1
git ×1
git-pull ×1
indexing ×1
libxml-ruby ×1
libxml2 ×1
logging ×1
methods ×1
mysql ×1
orm ×1
postgresql ×1
punctuation ×1
random ×1
scope ×1
solr ×1
sql-order-by ×1