-
Mix
ActionText::Attachableinto your mentionable person model:class Person < ApplicationRecord include ActionText::Attachable # ...
end
| class Notifier < ActionMailer::Base | |
| delivers_from '[email protected]' | |
| def welcome(user) | |
| @user = user # available to the view | |
| mail(:subject => 'Welcome!', :to => user.email_address) | |
| # auto renders both welcome.text.erb and welcome.html.erb | |
| end | |
| def goodbye(user) |
| # MODEL | |
| class Case < ActiveRecord::Base | |
| include Eventable | |
| has_many :tasks | |
| concerning :Assignment do | |
| def assign_to(new_owner:, details:) | |
| transaction do |
| import Foundation | |
| enum Environment: String { | |
| case development, staging, production | |
| } | |
| extension Environment { | |
| static var current: Environment { | |
| if isAppStore { | |
| return .production |
| import * as React from "react"; | |
| import { useMousePosition } from "~/hooks/useMousePosition"; | |
| /** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */ | |
| export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) { | |
| const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {}; | |
| const [mouseX, mouseY] = useMousePosition(); | |
| const positions = { x, y, h, w, mouseX, mouseY }; | |
| return ( | |
| <div |
| 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)); | |
| } |
| class Ticket < ActiveRecord::Base | |
| belongs_to :grouper | |
| belongs_to :user | |
| validate :user_cant_be_blacklisted, on: :confirmation | |
| validate :user_cant_double_book, on: :confirmation | |
| validate :grouper_cant_be_full, on: :confirmation | |
| validate :grouper_cant_have_occurred, on: :confirmation |
| /* | |
| 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> |
| Trix.config.textAttributes.red = { | |
| style: { backgroundColor: "red" } | |
| } | |
| element.editor.activateAttribute("red") | |
| // See available attribute options in: | |
| // https://github.com/basecamp/trix/blob/master/src/trix/config/text_attributes.coffee | |
| // https://github.com/basecamp/trix/blob/master/src/trix/config/block_attributes.coffee |
| http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query | |
| http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails | |
| #payload: [{"kind"=>"person"}] | |
| Segment.where("payload @> ?", [{kind: "person"}].to_json) | |
| #data: {"interest"=>["music", "movies", "programming"]} | |
| Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json) | |
| Segment.where("data #>> '{interest, 1}' = 'movies' ") | |
| Segment.where("jsonb_array_length(data->'interest') > 1") |