Skip to content

Instantly share code, notes, and snippets.

View ggoodale's full-sized avatar

Grant Goodale ggoodale

View GitHub Profile
User.find(params[:id]) rescue nil #=> Don't even get me started.
begin
a = Account.find(8675309) #=> Sadly, Jenny's not a user.
rescue
# I'm so cool I don't need to do anything here.
end
# If I ever find that Tommy...
a.update_attribute(:location, "bathroom wall")
begin
user = User.find(:frist) #=> Bill Frist?
user.update_attribute(:alive_or_dead) #=> Care to be more specific?
rescue => e
logger.error "Something bad happened" #=> Yeah, but what?
end
foo(nil) #=> nil
foo #=> Tue Jan 13 03:22:44 -0800 2009
def foo(a=Time.now.utc)
puts a
end
[3] <enki> [10:51 PM] ~>irb
>> x.blank?
NameError: undefined local variable or method `x' for main:Object
from (irb):1
>>
@ggoodale
ggoodale / gist:3137
Created July 29, 2008 18:20
Using a helper method in both a controller and a view.
class ApplicationController
protected
def iphone?
request.class.to_s.include?("CgiRequest") && request.user_agent.include?('iPhone')
end
end
class ApplicationHelper
def iphone?