Skip to content

Instantly share code, notes, and snippets.

# auth controller
def login
...
rescue Exception=> ex
logger.error ex.message
logger.info ex.backtrace.join("\n")
clear_session
flash[:warning] = "Incorrect login or password."
# in coverage and debugger, this line is not being called!?!
render :action => 'login', :layout=> 'simple'
@AJFaraday
AJFaraday / gist:3075534
Created July 9, 2012 10:05
stubs structure
def test_recalc_with_formula_error
Parameter.any_instance.stubs(:default_formula => "=whatever")
get :recalc, :id => @task
#...
ensure
Parameter.any_instance.unstub(:default_formula)
end
@AJFaraday
AJFaraday / gist:3713096
Created September 13, 2012 09:12
Something I'd love to see...
FooController callbacks:
index:
get_foos
new:
get_foo
set_foo_defaults
check_bar_rights
create:
get_foo
check_bar_rights
@AJFaraday
AJFaraday / gist:4275824
Created December 13, 2012 11:19
comments in database.yml
# The right way
#
#----------------------------------------------------------------
# Production database Real data
#----------------------------------------------------------------
#
development:
...
@AJFaraday
AJFaraday / gist:4335806
Created December 19, 2012 10:30
insanity?
# attempt to use underscored attributes
# e.g. labware_item_id would still return labwareitemid
def method_missing(method, *args, &block)
super method, args, block
rescue
if method.to_s.include?('_')
m = method.to_s
m = m.gsub('_', '').downcase
puts "#{method} is not present, trying #{m}"
return self.send m
@AJFaraday
AJFaraday / gist:5377324
Created April 13, 2013 06:32
DevsLoveBacon laptop orchestra
It's a simple idea, after enthusing the crowd at BACON with the
Text-to-music concept, a chance to try it out, en masse, and see
what happens.
So, to join in you need:
* to be at BACON
* a Linux or Mac laptop
* a clone of the repo at www.github.com/ajfaraday/Text-to-music
* read the readme, set it up
@AJFaraday
AJFaraday / gist:5582745
Last active December 17, 2015 08:49
brackets from cold
# any idea what's going on here?
>> ()
=> nil
>> (true)
=> true
>> ('string')
=> 'string'
>> (true,false)
SyntaxError: compile error
class Event < ActiveRecord
has_many :charges do
def self.total
self.collect{|charge|charge.total}.sum
end
end
@AJFaraday
AJFaraday / gist:5910052
Created July 2, 2013 15:02
Where did property A go?
hash_1 = {:string => 'string', :hash => {:property_A => 'a'}}
hash_2 = {:hash => {:property_B => 'b'}}
hash_1.merge(hash_2)
# => {:string=>"string", :hash=>{:property_B=>"b"}}
@AJFaraday
AJFaraday / gist:5916888
Last active December 19, 2015 07:09
routing issue
# server log
Started POST "/dashboards/33/fill_portlet_form" for 127.0.0.1 at 2013-07-03 11:12:04 +0100
[ FATAL: 11:12:04.143]
LoadError (Expected /home/ajfaraday/biorails/develop_5.0/app/controllers/admin/dashboards_controller.rb to define DashboardsController):
# routing file
scope :module => "admin" do
resources :dashboards do