activesupport

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

孤者浪人 提交于 2019-11-28 10:25:16
问题 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

How to add 10 days to current time in Rails

我怕爱的太早我们不能终老 提交于 2019-11-28 03:21:52
I tried doing something like Time.now + 5.days but that doesn't work, even though I vaguely remember seeing, and being very impressed, with being able to do something like 2.years etc. How do I do that in Rails 3? gunn Use Time.now + 10.days or even 10.days.from_now Both definitely work. Are you sure you're in Rails and not just Ruby? If you definitely are in Rails, where are you trying to run this from? Note that Active Support has to be loaded. Jonathan Julian days , years , etc., are part of Active Support, So this won't work in irb , but it should work in rails console . dj kaori This

How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?

痞子三分冷 提交于 2019-11-27 18:37:16
I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't. I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_json in a controller that returns a list of objects, but I want to control which attributes are returned. When code anywhere in my system does require 'json' I get this error message: TypeError: wrong argument type Hash (expected Data) I tried a couple of things

How to encode media in base64 given URL in Ruby

主宰稳场 提交于 2019-11-27 17:48:55
I'm trying to upload an image to PingFM. Their documentation says: media – base64 encoded media data. I can access this image via the URL. I tried (practically guessed) this: ActiveSupport::Base64.encode64(open("http://image.com/img.jpg")) But I get this error: TypeError: can't convert Tempfile into String from /usr/lib/ruby/1.8/base64.rb:97:in `pack' from /usr/lib/ruby/1.8/base64.rb:97:in `encode64' from (irb):19 from :0 The open method: open("http://image.com/img.jpg") is returning a Tempfile object, while encode64 expects a String. Calling read on the tempfile should do the trick:

Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) with cache_classes = true

為{幸葍}努か 提交于 2019-11-27 17:08:41
问题 I have a certain module which is used in a Rails 4.1.1 application module A extend ActiveSupport::Concern included do #Some code end end which is included in a class class Some include A end This works great with cache_classes=true in application.rb . Now, if I turn off the caching of classes, I get Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) exception upson starting the server. How should one deal with such an issue since reloading

How do I use Active Support core extensions?

跟風遠走 提交于 2019-11-27 06:28:26
I have Active Support 3.0.3 installed and Rails 3.0.3 with Ruby 1.8.7. When I try to use 1.week.ago I get NoMethodError: undefined method 'week' for 1:Fixnum from (irb):2 The other core extensions seem to work. I tried it on a friend's computer (same install specs and legacy versions are on his) with the same results. What gives? All of this is in IRB. Since using Rails should handle this automatically I'm going to assume you're trying to add Active Support to a non-Rails script. Read " How to Load Core Extensions ". Active Support's methods got broken into smaller groups in Rails 3, so we don

Convert UTC to local time in Rails 3

北城以北 提交于 2019-11-27 06:11:07
I'm having trouble converting a UTC Time or TimeWithZone to local time in Rails 3. Say moment is some Time variable in UTC (e.g. moment = Time.now.utc ). How do I convert moment to my time zone, taking care of DST (i.e. using EST/EDT)? More precisely, I'd like to printout "Monday March 14, 9 AM" if the time correspond to this morning 9 AM EDT and "Monday March 7, 9 AM" if the time was 9 AM EST last monday. Hopefully there's another way? Edit : I first thought that "EDT" should be a recognized timezone, but "EDT" is not an actual timezone, more like the state of a timezone. For instance it

How to encode media in base64 given URL in Ruby

回眸只為那壹抹淺笑 提交于 2019-11-27 04:13:44
问题 I'm trying to upload an image to PingFM. Their documentation says: media – base64 encoded media data. I can access this image via the URL. I tried (practically guessed) this: ActiveSupport::Base64.encode64(open("http://image.com/img.jpg")) But I get this error: TypeError: can't convert Tempfile into String from /usr/lib/ruby/1.8/base64.rb:97:in `pack' from /usr/lib/ruby/1.8/base64.rb:97:in `encode64' from (irb):19 from :0 回答1: The open method: open("http://image.com/img.jpg") is returning a

How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?

荒凉一梦 提交于 2019-11-26 22:42:19
问题 I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't. I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_json in a controller that returns a list of objects, but I want to control which attributes are returned. When code anywhere in my system does require 'json' I

Convert UTC to local time in Rails 3

本秂侑毒 提交于 2019-11-26 11:53:48
问题 I\'m having trouble converting a UTC Time or TimeWithZone to local time in Rails 3. Say moment is some Time variable in UTC (e.g. moment = Time.now.utc ). How do I convert moment to my time zone, taking care of DST (i.e. using EST/EDT)? More precisely, I\'d like to printout \"Monday March 14, 9 AM\" if the time correspond to this morning 9 AM EDT and \"Monday March 7, 9 AM\" if the time was 9 AM EST last monday. Hopefully there\'s another way? Edit : I first thought that \"EDT\" should be a