This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following lookups will be cached: | |
# | |
# User.find(123) | |
# User.find_by_id(123) | |
# User.find_by_username("Joe") | |
# User.find_by_email("joe@example.com") | |
class User < ActiveRecord::Base | |
cachable_model :find_by => [:username, :email] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module URI | |
# Safe alternative to URI.parse(uri_string).host to avoid exception being thrown | |
# on URLs with trailing spaces or invalid URLs. See also: | |
# http://www.practicalguile.com/2007/09/15/raising-uriinvalidurierror-from-a-perfectly-valid-uri/ | |
def self.host(uri_string) | |
begin | |
URI.parse(uri_string.try(:strip)).host | |
rescue URI::InvalidURIError | |
nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.before(:each, :behaviour_type => :controller) do | |
rescue_action_in_public! | |
end |