Skip to content

Instantly share code, notes, and snippets.

View leemcalilly's full-sized avatar

Lee McAlilly leemcalilly

View GitHub Profile
@leemcalilly
leemcalilly / Gemfile
Created June 27, 2020 16:50 — forked from dhh/Gemfile
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
// Required inside postcss.config.js
module.exports = {
important: true,
theme: {
container: {
center: true,
padding: '0.75rem'
},
# _form.html.erb
<%= f.fields_for :options do |builder| %>
<%= render 'option_fields', f: builder %>
<% end %>
# _option_fields.html.erb
<fieldset class='form-group'>
<%= f.hidden_field :account_id, value: current_user.account.id %>
<%= f.label :name, 'Option' %>
class ApplicationController < ActionController::Base
include Clearance::Controller
before_action :require_login
before_action :require_account
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private
<%= form_with(model: account, local: true) do |form| %>
<fieldset>
<%= form.label :name, 'Company Name' %>
<%= form.text_field :name %>
</fieldset>
<%= form.fields_for :user do |builder| %>
<fieldset>
<%= builder.label :email %>
class QuotesController < ApplicationController
before_action :set_quote, only: [:show]
before_action :require_login
skip_before_action :require_login, only: [:index, :show]
def show
end
def new
class ArtistsController < ApplicationController
before_action :set_artist, only: [:show, :edit, :update, :destroy]
skip_before_action :require_login, only: [:index, :show]
def index
@artists = Artist.all
end
def show
end
class Artist < ApplicationRecord
belongs_to :user
has_many :spoken_quotes, class_name: "Quote", foreign_key: :speaker_id
has_many :topic_quotes, class_name: "Quote", foreign_key: :topic_id
validates :user_id, presence: true
validates :name, presence: true, length: { maximum: 120 },
uniqueness: { case_sensitive: false }
end
class Quote < ApplicationRecord
belongs_to :user
belongs_to :speaker, class_name: "Artist"
belongs_to :topic, class_name: "Artist"
belongs_to :genre
delegate :medium, to: :genre, allow_nil: true
validates :user_id, presence: true
<%= form_for(@quote) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class='row'>
<div class='col'>
<div class='form-group'>
<%= f.label :speaker, 'Who said it?' %>
<%= f.collection_select :speaker_id, Artist.order(:name), :id, :name,
{prompt: 'Select an artist'}, {class: 'form-control select-artist'} %>
</div>