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
# config/environments/test.rb | |
ActiveSupport.on_load(:active_record_postgresqladapter) do | |
# For this optimization to work, you need to recreate your test database | |
self.create_unlogged_tables = true | |
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
resources :media, shallow: true, | |
constraints: ->(req) do | |
current_user = req.env["warden"].user(:user) | |
Flipper.enabled?(:media_uploads, current_user) | |
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 Chart < ApplicationRecord | |
validate do |chart| | |
schema = Rails.cache.fetch("vega_lite_schema/v5") do | |
Faraday.get("https://vega.github.io/schema/vega-lite/v5.json").body | |
end | |
JsonSchemaValidator.new(chart, schema: schema, json: vega_json, field: :vega_json).validate | |
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
# frozen_string_literal: true | |
# Via https://gist.github.com/ta1kt0me/6a7058d16621785d4f7038bde6cd3b98 | |
module RailsGeneratorFrozenStringLiteralPrepend | |
RUBY_EXTENSIONS = %w[.rb .rake].freeze | |
def render | |
return super unless RUBY_EXTENSIONS.include?(File.extname(destination)) | |
"# frozen_string_literal: true\n\n#{super}" |
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
# frozen_string_literal: true | |
class ExampleResource < Avo::BaseResource | |
include ResourceExtensions | |
field :id, as: :id | |
field :name, as: :text | |
index do | |
field :some_field, as: :text |
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
import { Controller } from "stimulus"; | |
import { get } from "@rails/request.js"; | |
import { PageSnapshot } from "@hotwired/turbo"; | |
export default class extends Controller { | |
static values = { hoverTime: Number }; | |
connect() { | |
this.element.addEventListener("mouseover", this.prefetch.bind(this)); | |
this.element.addEventListener("touchstart", this.prefetch.bind(this)); | |
} |
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
/* | |
ERB template chunk from The Feed's display of emails: | |
<section class="postings postings--feed-style" id="postings" | |
data-controller="pagination" data-pagination-root-margin-value="40px"> | |
<%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %> | |
<%= link_to(spinner_tag, url_for(page: @page.next_param), | |
class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %> | |
</section> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
... | |
</head> | |
<body data-controller="js"> | |
<%= yield %> | |
</body> | |
</html> |
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
// This code is to be used with https://turbo.hotwire.dev. By default Turbo keeps visited pages in its cache | |
// so that when you visit one of those pages again, Turbo will fetch the copy from cache first and present that to the user, then | |
// it will fetch the updated page from the server and replace the preview. This makes for a much more responsive navigation | |
// between pages. We can improve this further with the code in this file. It enables automatic prefetching of a page when you | |
// hover with the mouse on a link or touch it on a mobile device. There is a delay between the mouseover event and the click | |
// event, so with this trick the page is already being fetched before the click happens, speeding up also the first | |
// view of a page not yet in cache. When the page has been prefetched it is then added to Turbo's cache so it's available for | |
// the next visit during the same session. Turbo's default behavior plus this trick make for much more responsive UIs (non SPA). | |