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 Api::UsersController < ApplicationController | |
def show | |
if stale?(:last_modified => current_user.updated_at, :etag => current_user.updated_at) | |
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
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 |
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 Api::UsersController < ApiController | |
def show | |
if stale?(:last_modified => current_user.user_updated_at, :etag => current_user.user_updated_at) | |
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
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 |
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
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}" |
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
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 |
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 | |
before_save do | |
post.touch | |
end | |
before_destroy do | |
post.touch | |
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
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 |
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
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 |
OlderNewer