Skip to content

Instantly share code, notes, and snippets.

@dangalipo
dangalipo / gist:741838
Created December 15, 2010 10:20
please dont beat me karl
// stylesheets/partials/public/general.sass
#flash
border: solid 1px
float: right
font-size: 1.2em
margin-right: 232px
padding: 10px
#flash.error
@dangalipo
dangalipo / gist:761044
Created December 31, 2010 14:15
DARCY!!!!!!!
#in spec
before :each do
@supplier = Supplier.make
stub(Supplier).find(1) { @supplier }
stub(@supplier).save { true }
@user_a = User.make
@user_b = User.make
stub(@supplier).users { [@user_a, @user_b] }
end
class Manage::Products::SpecificationsController < ManageController
# POST /manage/products/1/specifications
#----------------------------------------------------------------------------
def create
raise 'foo'
# @product = Product.find(params[:product_id])
# @variant = @product.product_variants.find(params[:specification]["specable_id"])
#
# # TODO - needs to be fixed, comes from formtastic in the new form
@dangalipo
dangalipo / gist:762338
Created January 2, 2011 06:09
full trace
activerecord (3.0.0) lib/active_record/associations/association_proxy.rb:260:in `raise_on_type_mismatch'
activerecord (3.0.0) lib/active_record/associations/belongs_to_association.rb:23:in `replace'
activerecord (3.0.0) lib/active_record/associations.rb:1474:in `specification_type='
activerecord (3.0.0) lib/active_record/base.rb:1548:in `send'
activerecord (3.0.0) lib/active_record/base.rb:1548:in `attributes='
activerecord (3.0.0) lib/active_record/base.rb:1544:in `each'
activerecord (3.0.0) lib/active_record/base.rb:1544:in `attributes='
cancan (1.4.1) lib/cancan/controller_resource.rb:72:in `build_resource'
cancan (1.4.1) lib/cancan/controller_resource.rb:48:in `load_resource_instance'
cancan (1.4.1) lib/cancan/controller_resource.rb:30:in `load_resource'
@dangalipo
dangalipo / gist:794581
Created January 25, 2011 06:49
exception handling
def merge_suppliers
@supplier_from = Supplier.find(params[:id])
begin
@supplier_to = Supplier.find(params[:supplier_id])
rescue ActiveRecord::RecordNotFound
flash[:error] = "#{t('object.supplier')} #{t('messages.not_found')}"
redirect_to manage_supplier_path(@supplier_from.id)
end
@dangalipo
dangalipo / breadcrumb setter
Created March 9, 2011 06:28
helper or controller method?
def set_breadcrumbs_session(current, breadcrumbs)
if current.root?
breadcrumbs = [current.id]
else
parent_ids = []
current.parents.each{|c| parent_ids << c.id}
if parent_ids.include?(breadcrumbs.last)
breadcrumbs << current.id
else
if breadcrumbs.include?(current.id)
def generate_breadcrumbs(current, breadcrumbs)
if current.root?
[current.id]
elsif breadcrumbs.present?
traverse_breadcrumbs(current, breadcrumbs)
end
end
def traverse_breadcrumbs(current, breadcrumbs)
@dangalipo
dangalipo / searchtree
Created April 14, 2011 07:53
Why does it feel like im going about this the wrong way?
def index
if request.format == 'json'
if params[:product_type_id].present?
@search_trees = ProductType.find(params[:product_type_id]).search_trees
else
@search_trees = SearchTree.botttom_nodes
end
else
@search_trees = SearchTree.roots
end
def index
if request.format.json?
if params[:product_type_id].present?
@search_trees = ProductType.find(params[:product_type_id]).search_trees
else
@search_trees = SearchTree.bottom_nodes
end
else
@search_trees = SearchTree.roots
end
before :each do
login_as_admin!
end
before :all do
@search_tree_a = SearchTree.make!
@search_tree_b = SearchTree.make!
@search_tree_c = SearchTree.make!
@product_type = ProductType.make!
@search_tree_a.children << @search_tree_b