Skip to content

Instantly share code, notes, and snippets.

@dparfrey
dparfrey / confirm_controller.js
Created April 19, 2021 14:18
Confirmation dialog (non-UJS) for Rails 6, Hotwire/Stimulus, and Bootstrap 5. Uses vanilla Javascript.
// This is a replacement for the built-in Rails ujs confirmation method when using Bootstrap.
// Trying to hook into the built-in stuff is a pain, and changes with every Rails (now Hotwire)
// version.
import { Controller } from "stimulus";
import { Modal } from "bootstrap";
export default class extends Controller {
static values = {
title: String,
message: String,
@dalezak
dalezak / _form.html.erb
Last active April 15, 2024 12:13
Stimulus.js Toggle Controller to show and hide form elements based on select value
<div class="form-group">
<%= form.label :type, "Type", class: "font-weight-bold" %>
<%= form.select :type, ['TextQuestion', 'UrlQuestion'], { include_blank: true }, { class: "form-control", data: { action: "input->toggle#changed", target: "toggle.select" } } %>
</div>
<div class="form-group">
<%= form.label :name, "Name", class: "font-weight-bold" %>
<%= form.text_field :name, class: "form-control" %>
</div>
<div class="form-group" data-target="toggle.element" data-values="UrlQuestion">
<%= form.label :url, "URL", class: "font-weight-bold" %>
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@pjbelo
pjbelo / add_flash_types.md
Last active June 9, 2022 12:34
[Rails] Flash Types

In rails 5 you can use add_flash_types method. Just add it to ApplicationController and include the types you want:

# application_controller.rb
...
  add_flash_types :success, :warning, :danger, :info

on your controller use the appropriate type instead of 'notice':

@JuanVqz
JuanVqz / simple_form_bulma.rb
Last active June 18, 2024 15:06
Support for simple form with bulma css, copy and paste on config/initializers/simple_form_bulma.rb
# frozen_string_literal: true
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Default class for buttons
config.button_class = "button"
# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = "checkbox"
pt-BR:
simple_form:
"yes": 'Sim'
"no": 'Não'
required:
text: 'obrigatório'
mark: '*'
# You can uncomment the line below if you need to overwrite the whole required html.
# When using html, text and mark won't be used.
# html: '<abbr title="required">*</abbr>'
@mrluizandre
mrluizandre / pt-BR.yml
Last active December 30, 2022 06:00
Rails locale file for brazilian portuguese language pt-BR.yml
---
pt-BR:
activerecord:
errors:
messages:
record_invalid: 'A validação falhou: %{errors}'
restrict_dependent_destroy:
has_one: Não é possível excluir o registro pois existe um %{record} dependente
has_many: Não é possível excluir o registro pois existem %{record} dependentes
date:
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active July 16, 2024 23:32
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@mnishiguchi
mnishiguchi / rails_friendly_forwarding.md
Last active April 29, 2024 13:25
Rails, Devise - Friendly forwarding after sign in or log in
@lawso017
lawso017 / mentionable_trix.js.coffee
Last active July 6, 2022 10:13
@mentions with trix-editor and selectize.js
window.addEventListener "trix-initialize", (e) =>
Utility.TrixMentions.prepare($(e.target))