activesupport

rails 3.1 inflection problem

别来无恙 提交于 2019-12-07 13:11:30
问题 I have a Rails 3.1 app with the following 2 models class Listing < ActiveRecord::Base has_many :listing_saves end class Team < ActiveRecord::Base has_many :listing_saves has_many :saved_listings, through: :listing_saves, source: 'listing' end The Join model looks like this class ListingSave < ActiveRecord::Base belongs_to :team belongs_to :listing end Mow I think that there is an inflection problem because whenever I try to run my tests I get the following error (this is an example of an

Rails: execution expired on time_zone_select

假装没事ソ 提交于 2019-12-07 06:09:18
问题 The following exception comes up intermittently: An ActionView::Template::Error occurred execution expired vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' This is the full trace: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2

How do I get Rails TimeZone names from obsolete TZInfo identifiers?

倖福魔咒の 提交于 2019-12-07 04:13:31
问题 There is already a question which answers how to convert "America/Los_Angeles" to "Pacific Time (US & Canada)". However I want to convert "US/Pacific" and other obsolete time zones to Rails TimeZone. I am unable to find anything in the library which helps me accomplish this. 回答1: From the Rails ActiveSupport::TimeZone docs: The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones defined by the TimeZone class. If you need to use zones that

Testing ActiveSupport::TimeWithZone objects for equality

ぃ、小莉子 提交于 2019-12-06 21:41:22
问题 Can someone explain how d1 is greater than d2? They are the same damn dates (or atleast that is how they look to me). Loading development environment (Rails 3.0.8) ruby-1.9.2-p180 :001 > d1 = Event.first.updated_at => Thu, 22 Sep 2011 02:24:28 PDT -07:00 ruby-1.9.2-p180 :002 > d2 = Time.zone.parse("2011-09-22T02:24:28-07:00") => Thu, 22 Sep 2011 02:24:28 PDT -07:00 ruby-1.9.2-p180 :003 > d1.class => ActiveSupport::TimeWithZone ruby-1.9.2-p180 :004 > d2.class => ActiveSupport::TimeWithZone

Comparison between two ActiveSupport::TimeWithZone objects fails

时光怂恿深爱的人放手 提交于 2019-12-06 14:22:31
In my test suite, I have a failing test. expected[0]['date'] comes from SomeModel.first.created_at In a debugging console, I have the following: > expected[0]['date'] => Tue, 25 Mar 2014 16:01:45 UTC +00:00 > res[0]['date'] => Tue, 25 Mar 2014 16:01:45 UTC +00:00 > res[0]['date'] == expected[0]['date'] => false # wtf > res[0]['date'].class => ActiveSupport::TimeWithZone > expected[0]['date'].class => ActiveSupport::TimeWithZone > How is this possible ? I've tried to reproduce this problem (I tought maybe the == operator on TimeWithZone checks the reference, or something like this, but no...) :

Difference between 'in?' and 'include?' in Rails

怎甘沉沦 提交于 2019-12-05 18:48:41
I was going over Rails' ActiveSupport extensions and I came across the 'in?' method. To me, it looks and works exactly like the 'include?' method, but just in reverse. ([1..5]).include? 1 1.in? ([1..5]) I've been using the 'include?' method since I first started using Rails, so it's intriguing that there's another method that does exactly the same thing. Is there's some difference in the two methods that I'm missing? EDIT Is there any scenario where using 'in?' would benefit more than using 'include?' ? Because right now, all I can think is that 'in?' is a rather pointless method given

Access to Rails request inside ActiveSupport::LogSubscriber subclass

杀马特。学长 韩版系。学妹 提交于 2019-12-05 13:48:38
I am trying to make a bit of a custom Rails logger which ultimately will log to a database. However, I don't have access to things like the request object, which I very much would like to have. I'm currently trying to use the LogSubscriber (notification) interface to do the bulk of this; perhaps this is not the right approach. I do know I could abuse Thread.current[] but I was hoping to avoid doing that. Here's the code I have which is as basic as I can get it for an example. This is loaded in an initializer. module RequestLogging class LogSubscriber < ActiveSupport::LogSubscriber def process

Custom Inflections not working on rails3?

霸气de小男生 提交于 2019-12-05 12:06:42
I'm using Rails (3.0.1) and have the following code in initializers/inflections.rb ActiveSupport::Inflector.inflections do |inflect| inflect.irregular('nursery', 'nurseries') end From the console I'm getting: "nursery".pluralize => "nurseries" "nurseries".singularize => "nurseries" I should be getting: "nurseries".singularize => "nursery" Any ideas? 来源: https://stackoverflow.com/questions/4028992/custom-inflections-not-working-on-rails3

Rails: execution expired on time_zone_select

我们两清 提交于 2019-12-05 11:15:42
The following exception comes up intermittently: An ActionView::Template::Error occurred execution expired vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' This is the full trace: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require' vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency' vendor/bundle/ruby/1.9.1/gems

How to fix difference in behavior of activesupport 3.0.0 compare to 2.x?

限于喜欢 提交于 2019-12-04 23:41:25
问题 I am using Hash#to_xml in my Sinatra application. It did work till I moved to actviesupport 3.0.0 Is there a difference in usage of activesupport in 3.0.0? For example this works fine gem 'activesupport', '2.3.5' require 'active_support' {}.to_xml and gem 'activesupport', '3.0.0' require 'active_support' {}.to_xml generates: NoMethodError: undefined method `to_xml' for {}:Hash 回答1: ActiveSupport no longer loads all its components when you require it. This allows you to cherry-pick the