activesupport

How can I automatically reload gem code on each request in development mode in Rails?

亡梦爱人 提交于 2019-12-11 03:47:31
问题 I am developing a Rails app where most of the code not specific to the app has been written inside of various gems, including some Rails engines and some 3rd party gems for which I am enhancing or fixing bugs. gem 'mygem', path: File.expath_path('../../mygem', __FILE__) Since a lot of the code in these gems is really part of the app, it's still changing frequently. I'd like to be able to utilize the Rails feature where code is reloaded on each request when in development (i.e. when config

ActiveSupport::JSON.decode does not properly handle literal line breaks

寵の児 提交于 2019-12-11 03:26:34
问题 Is this the expected behavior? Note how the line break character gets lost. ruby-1.9.2-p136 :001 > ActiveSupport::JSON.decode("{\"content\": \"active\n\nsupport\"}") => {"content"=>"active\nsupport"} The same happens with unicode-escaped line breaks: ruby-1.9.2-p136 :002 > ActiveSupport::JSON.decode("{\"content\": \"active\u000a\u000asupport\"}") => {"content"=>"active\nsupport"} I'm using rails 3.0.3. 回答1: I eventually came across this ticket: https://rails.lighthouseapp.com/projects/8994

How do I use Active Support core extensions?

余生长醉 提交于 2019-12-11 01:54:31
问题 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. 回答1: 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

Styling the date fields of a Rails date_select

不羁岁月 提交于 2019-12-10 16:12:36
问题 In Rails' forms, date select drop-downs are easy: <%= f.label :my_date %> <%= f.date_select :my_date %> Then I get 3 select drop-downs for the year, month and day. Is there an easy way to add HTML between these select elements without using JavaScript? I want to be able to style and label them nicer. 回答1: Convert it to a text field and add a JQuery datepicker or similar. Theres a good guide here, http://railscasts.com/episodes/213-calendars 回答2: You can easily style them with CSS as each part

uninitialized constant ActiveSupport::CoreExtensions

半世苍凉 提交于 2019-12-10 13:14:34
问题 I'm attempting to integrate jquery's datepicker with formtastic as detailed here I've followed the directions exactly, but am getting "uninitialized constant ActiveSupport::CoreExtensions" when running this code: <%= semantic_form_for @item, :html => { :multipart => true, :class => 'form'} do |f| %> <div class="group"> <%= f.label :create_date, :class => 'label' %> <%= f.input :create_date, :as => :datepicker %> </div> <% end %> I attempted to put this in my config/application.rb: require

can't activate activesupport (>= 2.3.2, runtime), already activated activesupport-2.1.2. what does it mean?

房东的猫 提交于 2019-12-10 03:41:46
问题 while trying to start some old revision of an opensource rails project confronted with a cloudy error message: "can't activate activesupport (>= 2.3.2, runtime), already activated activesupport-2.1.2" What does it mean? Either versions of rails and activesupport are installed on my box. I'm confused... 回答1: Generally, a gem or plugin is loading 2.1.2 before Rails attempts to load 2.3.2. Best way to figure it out might be to comment out each gem requirement in environment.rb one at a time and

3.days.ago, 2.hours.from_now etc without Rails?

北慕城南 提交于 2019-12-09 07:36:22
问题 Some book mentioned some gem to decorate numbers with #days , #megabytes , #minutes etc. Is this only in ActiveSupport, or is there a smaller gem that provides this functionality for use in (small) non-rails gems? I want to use this functionality as part of a DSL in a tiny little gem. 回答1: I'm not sure if there's another gem available besides ActiveSupport , but it would be really straight-forward to make a small version yourself: class Fixnum SECONDS_IN_DAY = 24 * 60 * 60 def days self *

Overriding methods in an ActiveSupport::Concern module which are defined by a class method in the same module

守給你的承諾、 提交于 2019-12-09 02:51:44
问题 I have an ActiveSupport::Concern module which looks roughly like the following: module MyModel module Acceptance extend ActiveSupport::Concern included do enum status: [:declined, :accepted] end def declined! self.status = :declined # some extra logic self.save! end def accepted! self.status = :accepted # some extra logic self.save! end end end This is only ever going to be included into ActiveRecord classes, hence the use of enum . Basically, I'm overriding the declined! and accepted!

ActiveRecord validation for nil

孤者浪人 提交于 2019-12-08 09:38:24
问题 I am trying to write an active record validation that allows any string but does not allow nil. The problem with validates_presences_of is that it returns false for "" or " " which I want to consider valid. I have also tried to do validates_length_of :foo, :minimum => 0 which did not work I have also tried t o do validates_length_of :foo, :minimum => 0, :unless => :nil? which also did not work. Both of these allowed for nil values to be set and the validation still returns true. Am i missing

Comparison between two ActiveSupport::TimeWithZone objects fails

亡梦爱人 提交于 2019-12-08 02:15: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