Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee McAlilly leemcalilly

View GitHub Profile
@leemcalilly
leemcalilly / Gemfile
Created Jun 27, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View 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
View gist:f3519888f3adb5a7f33cce26cc11baf4
// Required inside postcss.config.js
module.exports = {
important: true,
theme: {
container: {
center: true,
padding: '0.75rem'
},
View gist:1e2927fad26cfa1481a51899cfcd881b
# _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' %>
View gist:68ca89f3c9e193266c9b9d9287263978
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
View gist:83a9ff2248c35b3e7c498466bb2829e7
<%= 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 %>
View quotes_controller.rb
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
View artists_controller.rb
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
View artist.rb
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
View quote.rb
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
View _form.html.erb
<%= 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>