Tag: activesupport

在Rails之外使用Rails 3的ActiveSupport核心扩展

我正在开发一个使用ActiveSupport核心扩展的问题。 我曾经使用AS 2.3.8,但是一旦我想将它移植到3b4,扩展停止工作,我的testing结果充满了行,如: undefined method `blank?' for "something":String 我已经通过gem "activesupport"然后require "active_support" 还有什么我需要打电话来包含这些扩展? 谢谢

我如何使用Active Support核心扩展?

我已经安装了Active Support 3.0.3,Rails 3.0.3和Ruby 1.8.7。 当我尝试使用1.week.ago我得到 NoMethodError: undefined method 'week' for 1:Fixnum from (irb):2 其他核心扩展似乎工作。 我在朋友的电脑上试了一下(相同的安装规格和旧版本),结果相同。 是什么赋予了? 所有这些都在IRB中。

什么是Rails模块中的mattr_accessor?

我在Rails文档中找不到这个,但是在正常的Ruby 类中, 'mattr_accessor'是'attr_accessor' (getter&setter)的模块推论。 例如。 在一个class级 class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end end 例如。 在一个模块中 module Authentication mattr_accessor :current_user def login @current_user = session[:user_id] || nil end end 这个帮助器方法由ActiveSupport提供。