Skip to content

Instantly share code, notes, and snippets.

View johnnaegle's full-sized avatar
🐈
I'm here live, I'm not a cat

John Naegle johnnaegle

🐈
I'm here live, I'm not a cat
View GitHub Profile
class Api::UsersController < ApplicationController
def show
if stale?(:last_modified => current_user.updated_at, :etag => current_user.updated_at)
end
end
end
class User < ActiveRecord::Base
COLUMNS_TO_EXCLUDE_FROM_CACHING = ["id", "updated_at", "created_at", "last_request_at"].freeze
COLUMNS_FOR_CACHING = (User.column_names - COLUMNS_TO_EXCLUDE_FROM_CACHING).freeze
before_validation do
unless (COLUMNS_FOR_CACHING & changed).empty?
self.user_updated_at = Time.now
end
true
end
end
class Api::UsersController < ApiController
def show
if stale?(:last_modified => current_user.user_updated_at, :etag => current_user.user_updated_at)
end
end
end
class Post < ActiveRecord::Base
has_many :comments, :dependent => :destroy, :inverse_of => :post
accepts_nested_attributes_for :comments, :allow_destroy => true
end
class Comment < ActiveRecord::Base
belongs_to :post, :inverse_of => :comments
end
post = Post.create!
post.attributes = {
:comments_attributes => {
"0" => {:body =>
Lorem::Base.new('words', 50).output.split(" ").shuffle.join(' ')
}
}
}
puts "Updated at: #{post.updated_at.to_f}"
INSERT INTO "posts" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"
[["created_at", Sat, 15 Mar 2014 03:35:32 UTC +00:00], ["updated_at", Sat, 15 Mar 2014 03:35:32 UTC +00:00]]
COMMIT
Updated at: 1394854532.1633868
BEGIN
INSERT INTO "comments" ("body", "created_at", "post_id", "updated_at") VALUES
($1, $2, $3, $4) RETURNING "id" [["body", "Lorem sit dolor vitae amet, blandit vitae consectetuer
class Comment < ActiveRecord::Base
belongs_to :post, :inverse_of => :comments
before_save do
post.touch
end
before_destroy do
post.touch
end
BEGIN
INSERT INTO "posts" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"
[["created_at", Sat, 15 Mar 2014 03:41:25 UTC +00:00], ["updated_at", Sat, 15 Mar 2014 03:41:25 UTC +00:00]]
COMMIT
Updated at: 1394854885.189413
BEGIN
UPDATE "posts" SET "updated_at" = '2014-03-15 03:41:30.205245' WHERE "posts"."id" = 7
# 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)
class Post < ActiveRecord::Base
validates :name, :presence => true
has_many :comments, :inverse_of=>:post, :dependent=>:destroy, :autosave=>true
end
class Comment < ActiveRecord::Base
belongs_to :post, :inverse_of=>:comments
scope :model, -> {where(:index => false)}
end