小编Bog*_*iev的帖子

在MySQL中按day_of_week排序

如何通过包含星期几名称的varchar列来订购mysql结果?

请注意,星期一应该先行,而不是星期日.

mysql sql sql-order-by dayofweek

12
推荐指数
2
解决办法
2万
查看次数

Ruby on Rails中的日志轮换/清除

如何在rails上的ruby中的test.log和development.log上设置自动清理?

是否有设置在服务器启动和测试运行时自动删除开发和测试日志?

logging ruby-on-rails

9
推荐指数
2
解决办法
1万
查看次数

黑客ActiveRecord:添加全局命名范围

我试图为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?

ruby activerecord ruby-on-rails

9
推荐指数
2
解决办法
2543
查看次数

在方法定义中使用$ 1,$ 2等全局变量

给出以下两段代码:

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将被以同样的方式,就好像块的方法定义中给出的评价?

ruby scope pseudo-globals

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

Ruby性能:使用define_method或eval定义方法

在查看ActiveSupport源代码时,我注意到有时eval会在define_method足够的地方使用.

示例:ActiveSupport:Module.delegate

我认为define_method更干净,更安全的做事方式.是什么带来的好处evaldefine_method?性能,内存使用,还有其他什么?

ruby methods eval metaprogramming

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

PostgreSQL:按随机天数更改日期

如何在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)

sql random postgresql date

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

ORM框架

我需要收集有关现有ORM解决方案的一些信息.请随时写下任何编程语言.

你能说出你曾经使用过的最好的ORM框架吗?为什么它比其他框架更好?

comparison orm frameworks

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

libxml-ruby无法在x86_64加载

我们在服务器端遇到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

重新安装宝石没有帮助可以有人建议做什么?

ruby elf libxml2 libxml-ruby

5
推荐指数
3
解决办法
5625
查看次数

Solr:在索引之前剥离标点符号

我遇到了从solr索引中去除标点符号的问题当标点符号紧跟在一个单词后面时,这个单词没有正确编入索引.

例如:如果我们索引"hello,John",则不会通过关键字"hello"找到资产,而如果我们在单词"hello"之后删除逗号则不会出现问题.

是否有任何FilterFactory假设剥离标点符号?有任何想法吗?

谢谢,波格丹.

indexing solr punctuation filterfactory

5
推荐指数
2
解决办法
4969
查看次数

使 git pull 显示更新文件的当前目录的相对路径

如果我的当前目录是 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)

git relative-path git-pull

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