Skip to content

Instantly share code, notes, and snippets.

class InvoiceForm
attr_reader :params
def initialize(params)
@params = params
end
def billing_date
Time.new(params[:year], params[:month], params[:day]) if time_data_present?
rescue ArgumentError
end
@attilagyorffy
attilagyorffy / css_colour_validator.rb
Created October 29, 2011 12:27
CSS colour validation in Rails 3
# Put this file under Rails.root /lib
class CssColourValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return false unless value
record.errors[attribute] << (options[:message] || 'is not a valid CSS colour') unless ::HexadecimalColourValidator.matches?(value) or ::WebSafeColourValidator.matches?(value)
end
end
@nicalpi
nicalpi / devise.rb
Created October 13, 2011 11:04
Omniauth multiple facebook login strategy
# initializers/devise.rb
config.omniauth :facebook, [APP_ID], [APP_SECRET]
config.omniauth :facebook_app1, [APP_ID], [APP_SECRET], :iframe => true, :scope => 'publish_stream,offline_access,email'
config.omniauth :facebook_app2, [APP_ID], [APP_SECRET], :iframe => true, :scope => 'publish_stream,offline_access,email'