activesupport

What is mattr_accessor in a Rails module?

六眼飞鱼酱① 提交于 2019-11-29 18:47:55
I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is the Module corollary for 'attr_accessor' (getter & setter) in a normal Ruby class . Eg. in a class class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end end Eg. in a module module Authentication mattr_accessor :current_user def login @current_user = session[:user_id] || nil end end This helper method is provided by ActiveSupport . Avdi Rails extends Ruby with both mattr_accessor (Module accessor) and cattr_accessor (as well as _ reader / _writer versions). As

Uninitialized Constant TZInfo::InvalidTimezoneIdentifier (NameError) - Rails 4

别等时光非礼了梦想. 提交于 2019-11-29 16:34:21
I'm in the process of upgrading a Rails 3.2 app to Rails 4.1. Whenever I try to start the console or server though, I come across this error: C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support /core_ext/time/zones.rb:70:in `rescue in find_zone!': uninitialized constant TZI nfo::InvalidTimezoneIdentifier (NameError) from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a ctive_support/core_ext/time/zones.rb:55:in `find_zone!' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.1.0.beta1/lib/a ctive_support/railtie.rb:20:in `block in <class

validates_inclusion_of no longer working the same in Rails 4.1?

一曲冷凌霜 提交于 2019-11-29 14:31:51
问题 The following code made sure that a time_zone chose is within the time zones in ActiveSupport::TimeZone.us_zones : validates_inclusion_of :time_zone, in: ActiveSupport::TimeZone.zones_map(&:name) Worked great in Rails 4.0. Just upgraded to Rails 4.1 and I'm getting this error on my index page (so just simply viewing the models): An object with the method #include? or a proc, lambda or symbol is required, and must be supplied as the :in (or :within) option of the configuration hash I'm

Error while trying to load the gem 'devise. ActiveSupport: Duration can't be coerced into Integer

不问归期 提交于 2019-11-29 12:03:47
问题 I've been trying to fix this error for a while now without finding any helpful, help please. I'm trying to run migrations on my ROR app using the devise gem. But I get an error from ActiveSupport 'Duration can't be coerced into Integer'. this happened then I try to run: rake db:migrate I'm not sure if it has something to do with the code on the migrations or if it is something about a new devise version. This is the error message: /home/sam/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems

How to convert MS excel date from float to date format in Ruby?

∥☆過路亽.° 提交于 2019-11-29 08:48:47
问题 Trying to parse and XLSX file using roo gem in a ruby script. In excel dates are stored as floats or integers in the format DDDDD.ttttt, counting from 1900-01-00 (00 no 01) . So in order to convert a date such as 40396 - you would take 1900-01-00 + 40396 and you should get 2010-10-15, but I'm getting 2010-08-08. I'm using active_support/time to do calculation like so: Time.new("1900-01-01") + 40396.days Am I doing my calculation wrong or is there a bug in active support? I'm running ruby 1.9

Testing a concern / module that uses ActiveRecord

☆樱花仙子☆ 提交于 2019-11-29 08:09:44
问题 SCENARIO I have extracted a concern called Taggable . It's a module that allows any model to support tagging. I have included this concern/module into models like User , Location , Places , Projects . I want to write tests for this module, but don't know where to start. QUESTION 1. Can I do isolation testing on the Taggable concern? In the example below the test fails because the test is looking for a dummy_class table . I'm assuming it's doing this because of the has_many code in Taggable so

How do I avoid the circular argument reference warning in activesupport

馋奶兔 提交于 2019-11-29 05:25:23
How do I avoid the circular argument reference warning in activesupport. Happens on ruby 2.2.0 /home/ec2-user/apps/foo_prod/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now /home/ec2-user/apps/foo_prod/shared/bundle/ruby/2.2.0/gems/ruby-ole-1.2.11.7/lib/ole/types/base.rb:265: warning: duplicated key at line 266 ignored: 4095 This is compass issue here . They haven't release new version yet so you may need to wait for it. Use Rails 3.2.22 gem 'rails', '3.2.22' OR warning fixes in version 1.2.11.8: bundle

Rails ActiveSupport: How to assert that an error is raised?

强颜欢笑 提交于 2019-11-29 00:53:19
I am wanting to test a function on one of my models that throws specific errors. The function looks something like this: def merge(release_to_delete) raise "Can't merge a release with itself!" if( self.id == release_to_delete.id ) raise "Can only merge releases by the same artist" if( self.artist != release_to_delete.artist ) #actual merge code here end Now I want to do an assert that when I call this function with a parameter that causes each of those exceptions, that the exceptions actually get thrown. I was looking at ActiveSupport documentation, but I wasn't finding anything promising. Any

Rails ActiveSupport Time Parsing?

天大地大妈咪最大 提交于 2019-11-28 15:59:51
Rails' ActiveSupport module extends the builtin ruby Time class with a number of methods. Notably, there is the to_formatted_s method, which lets you write Time.now.to_formatted_s(:db) to get a string in Database format, rather than having to write ugly strftime format-strings everywhere. My question is, is there a way to go backwards? Something like Time.parse_formatted_s(:db) which would parse a string in Database format, returning a new Time object. This seems like something that rails should be providing, but if it is, I can't find it. Am I just not able to find it, or do I need to write

What is mattr_accessor in a Rails module?

别说谁变了你拦得住时间么 提交于 2019-11-28 13:44:31
问题 I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is the Module corollary for 'attr_accessor' (getter & setter) in a normal Ruby class . Eg. in a class class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end end Eg. in a module module Authentication mattr_accessor :current_user def login @current_user = session[:user_id] || nil end end This helper method is provided by ActiveSupport . 回答1: Rails extends Ruby with