This file contains hidden or 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
require 'graphiti' | |
class User; end | |
class Post; end | |
class UserResource < Graphiti::Resource | |
attribute :id, :integer_id, writable: false | |
has_many :posts | |
end |
This file contains hidden or 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
require 'graphiti' | |
class PostResource < Graphiti::Resource | |
attribute :id, :integer_id, writable: false | |
attribute :title, :string, writable: true | |
end | |
params = { | |
data: { | |
id: 123, |
This file contains hidden or 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
require 'json' | |
require 'active_support/all' | |
# | |
# Monkeypatch Hash class in order to be able to compare both version | |
# | |
class Hash | |
def as_json(options = nil) #:nodoc: | |
# create a subset of the hash by applying :only or :except | |
subset = if options |
This file contains hidden or 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
Rails.application.config.after_initialize do | |
ActiveSupport.on_load(:action_text_content) do | |
class_eval do | |
attr_accessor :rich_text | |
def attachment_for_node(node, with_full_attributes: true) | |
attachment = ActionText::Attachment.from_node(node, rich_text&.find_preloaded_attachable(node)) | |
with_full_attributes ? attachment.with_full_attributes : attachment | |
end |
This file contains hidden or 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# gem "rails", "~> 5.1.0" # works |
This file contains hidden or 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
## | |
# PreloadCounts | |
# | |
# Usage: | |
# collection = Post.limit(10).preload_counts(:users) | |
# collection.first.users.count # fires one query to fetch all counts | |
# collection[1].users.count # uses the cached value | |
# collection.last.users.count # uses the cached value | |
# | |
# Call `::PreloadCounts.enable!` inside of an initializer to enable preloading of association counts |
This file contains hidden or 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
@mixin responsive-sprite($map, $icon){ | |
$icon-file: sprite-file($map, $icon); | |
$icon-width: image-width($icon-file); | |
$icon-height: image-height($icon-file); | |
$sprite-file: sprite-path($map); | |
$sprite-width: image-width($sprite-file); | |
$sprite-height: image-height($sprite-file); | |
$space-top: floor(nth(sprite-position($map, $icon), 2)); |
This file contains hidden or 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
@import "svg-sprites.css"; // client-side import; just like a large sprite image |