Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee McAlilly leemcalilly

View GitHub Profile
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 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 gist:45609209623b147d388717af814ed4bf
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 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_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>
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
accepts_nested_attributes_for :speaker
View gist:ada1bfc873eed6db6efd
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// load all grunt tasks
View gist:61e2d213d148c3814a42
haml: {
files: ['<%= yeoman.app %>/{layout,snippets,templates,templates/customers}/*.haml'],
tasks: ['haml']
},
update: {
files: ['<%= yeoman.app %>/{layout,snippets,templates,templates/customers}/*.liquid'],
tasks: ['copy']
},
View gist:7269928
$('#Helium').on('ready', function(e){
console.log('ready');
$('#Helium').on('add-to-cart', function(e, sku){
console.log('added '+ sku + ' to cart');
_gaq.push(["_trackEvent", "Helium Cart", "Add To Cart", "Peruvian Strap", "Dick Dale"]);
});
});
View gist:5629182
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "person_#{n}@example.com"}
password "secret"
password_confirmation "secret"
factory :admin do
after(:create) {|user| user.add_role(:admin)}
end
end