Skip to content

Instantly share code, notes, and snippets.

View kirkbushell's full-sized avatar

Kirk Bushell kirkbushell

  • Tectonic Digital
  • Sydney
View GitHub Profile
@kirkbushell
kirkbushell / whatever
Created August 15, 2011 00:06
nested models problem
#models
class Link < ActiveRecord::Base
has_many :link_urls
accepts_nested_attributes_for :link_urls, :allow_destroy => true #, :reject_if => lambda { |a| a[:url].blank? }
end
class LinkUrl < ActiveRecord::Base
belongs_to :link
end
# in controller method
@user = User.find_by_email(params[:email])
if @user.nil?
flash.now[:error] = 'No user found by that email address'
end
# view (in haml)
- unless flash.nil?
- if flash[:notice]
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
production:
adapter: mysql
# flash partial
- flash.each do |type,value|
- unless value.nil?
%div{:class => type.to_s}
%div
%span
= value
- unless object.nil?
%ul
- object.errors.full_messages.each do |msg|
conditions = {}
conditions[:title.matches] = '%'+@search_value+'%'
conditions[:description.matches] = '%'+@search_value+'%'
conditions[:status] = params[:show] if params[:show] != 'all'
conditions = {}
conditions.merge({:first_name.matches => '%'+@search_value+'%'} | {:last_name.matches => '%'+@search_value+'%'}) unless @search_value.blank?
@kirkbushell
kirkbushell / gist:1702294
Created January 30, 2012 03:25
rspec mock issue
require "spec_helper"
describe UserMailer do
describe "registration_email" do
@user = mock_model(User, :email => 'some@email.com', :first_name => 'john')
let(:mail) { UserMailer.registration_email(@user) }
it "renders the headers" do
mail.subject.should eq("Welcome to ScreenZone!")
@kirkbushell
kirkbushell / gist:1721258
Created February 2, 2012 03:34
Confirmation validation conditional
validates :password_confirmation, :presence => true, :if => Proc.new { |u| !u.password.blank? && u.password_confirmation.present? }
# PRODUCT MODEL
has_many :product_people
has_many :people, :through => :product_people
accepts_nested_attributes_for :people
# PRODUCTS IN ACTIVE ADMIN
f.inputs "Cast" do
f.has_many :product_people do |p|
p.input :name
@kirkbushell
kirkbushell / paginator.js
Created March 28, 2013 04:07
Paginator module for AngularJS, in combination with Laravel's paginator class
/**
* Paginator
*
* The paginator can be used within any controller to easily set up
* some pagination options, including number of pages, page navigation
* and more. It is built to work with Laravel's own pagination library,
* which returns data in a particular format.
*
* Usage:
* Before you can use paginator, make sure you specify the URLs to your pagination