Skip to content

Instantly share code, notes, and snippets.

View leemcalilly's full-sized avatar

Lee McAlilly leemcalilly

View GitHub Profile
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 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 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 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
<%= 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>
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
$('#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"]);
});
});
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
it "is non nil" do
user = FactoryGirl.create(:user)
user.email != nil
end
validates :password, :presence => { :on => :create },
:confirmation => true,
length:{ in: 6..40 }, if: ->{ crypted_password.blank? }