This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first = Post.create!(:name => "First") | |
first.comments.create!(:index => true) | |
first.comments.create!(:index => false) | |
puts "first.comments.count: #{first.comments.count}" | |
puts "first.comments.model.count: #{first.comments.model.count}" | |
puts "first.comments.where(:index => false).count: #{first.comments.where(:index => false).count}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comment < ActiveRecord::Base | |
belongs_to :post, :inverse_of=>:comments | |
scope :not_index, -> {where(:index => false)} | |
end | |
first = Post.create!(:name => "First") | |
first.comments.create!(:index => true) | |
first.comments.create!(:index => false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts Post.new.comments.model | |
> Comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.0.4' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'activesupport', '4.0.4' | |
require 'active_support/time' | |
require 'active_support/time_with_zone' | |
require 'active_support/core_ext/date_time/zones.rb' | |
require 'minitest/autorun' | |
class UserTest < MiniTest::Unit::TestCase | |
def test_no_milliseconds | |
time = ActiveSupport::TimeWithZone.new(Time.now, Time.find_zone!('UTC')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> bundle exec rails c | |
[1] pry(main)> Time.now.in_time_zone.as_json | |
=> "2014-04-08T03:22:34.472Z" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveSupport | |
class TimeWithZone | |
def as_json(options = nil) | |
if ActiveSupport::JSON::Encoding.use_standard_json_time_format | |
xmlschema | |
else | |
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [2013,10,12,60]; | |
var date = data.slice(0,3); | |
var payload = data.slice(3); | |
var result = [new Date(date[0], date[1], date[2])]; | |
if (payload.length > 0) { | |
for (item in payload) { | |
result.push(payload[item]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var item in payload) { | |
result.push(payload[item]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Issue < ActiveRecord::Base | |
enum :status => {:open => 1, :closed => 2, :reopened => 3, :inprogress => 4} | |
end |