Skip to content

Instantly share code, notes, and snippets.

View patrick99e99's full-sized avatar

Patrick Collins patrick99e99

  • collinator studios
  • Saratoga Springs, Utah
View GitHub Profile
# controller action
def result_list
type = (params[:newsletter_id].to_i.zero? ? 'PdfList' : 'Newsletter').constantize
result_list = type.find(params[:result_list_id])
unless result_list.in_progress?
call_rake :result_list, :function => params[:submit_button],
:result_list_id => result_list.id,
:search => (params[:search].blank? ? nil : params[:search].strip),
:search_scope => params[:search_scope],
class Photo
belongs_to :photo_album
def set_cover(cover)
if cover
photo_album.cover = self
elsif photo_album.cover.nil?
# set album cover to first photo album if no cover has been set.
photo_album.cover = photo_album.photos.first
class Admin::PhotosController < Admin::TablesController
cache_sweeper :photo_sweeper, :only => [:create, :update, :destroy]
# standard methods for index, show, new, edit, update, destroy
end
def set_cover(should_be_cover, photo)
if should_be_cover
cover = photo
elsif cover.nil?
# set album cover to first photo album if no cover has been set.
cover = photos.first
end
end
class Contact < ActiveRecord::Base
with_options :dependent => :destroy do |parent|
parent.has_many :phones
parent.has_many :emails
parent.has_many :addresses
parent.has_one :photo
parent.has_one :user
end
require 'spec_helper'
include ActionView::Helpers
describe Content do
def rendered_contents
ContentRenderer.new(nil, {:contents => @contents, :skip_ids => true}).render_contents
end
class Vcard < ActiveRecord::Base
def import
@card = Vpim::Vcard.decode(self.data).first
get_data
find_contact
if @contact
def import
parse_card
if found_contact
update_contact
else
create_contact
end
require 'spec_helper'
describe ResultList do
before(:all) do
ResultList.all.map(&:destroy)
Contact.all.map(&:destroy)
@result_list = ResultList.create!
5.times do
require 'spec_helper'
include ActionView::Helpers
describe Content do
def rendered_contents
ContentRenderer.new(nil, {:contents => @contents, :skip_ids => true}).render_contents
end