Skip to content

Instantly share code, notes, and snippets.

View DBA's full-sized avatar

Diogo Almeida DBA

  • Apple, Inc.
View GitHub Profile
class GeneralPurposeFormBuilder < ActionView::Helpers::FormBuilder
%w[text_field text_area collection_select].each do |method_name|
define_method(method_name) do |field_name, *args|
@template.content_tag(:div, field_label(field_name, *args) +
"<br />" + super + field_hint(field_name, *args),
:id => field_container_name(field_name),
:class => "form_field")
end
end
# This custom version of the authenticate method allows the user to use login or email as unique keys.
# Please note that if using this method it's highly recommended that you make the email property, of the user model, a required one.
# Also consider adding a unique index to the email field. For that create a migration with: add_index :users, :email, :unique => true
# It's equally advisable to remove the nullable option from the email field.
def self.authenticate(login, password)
return nil if login.blank? || password.blank?
u = find :first, :conditions => ['(email = ? OR login = ?) and activated_at IS NOT NULL', login, login] # need to get the salt
u && u.authenticated?(password) ? u : nil
end
Feature: Manage love lines
In order to manage the love lines of the Love Coach
As a registered user
I want to be able to create, edit and remove love lines
Background:
Given I have at least one skin color
And I have at least one hair color
And I have at least one eye color
And I have at least one line type
Given /I have at least one (.+)/ do |object_type|
case object_type
when "skin color"
Factory(:skin_color)
when "hair color"
Factory(:hair_color)
when "eye color"
Factory(:eye_color)
when "line type"
Factory(:love_line_type)
[71, 80] in /Users/dba/work/gnomeslab.com/products/playergadget/site/vendor/plugins/authlogic_openid/lib/authlogic_openid/acts_as_authentic.rb
71 return false if perform_validation && authenticate_with_openid? && !authenticate_with_openid
72 return false if new_record? && (!openid_complete? && @openid_error.nil?)
73
74 result = super
75 debugger
=> 76 yield(result) unless block.nil?
77 result
78 end
79
require 'builder'
class LogEntry
include Mongoid::Document
include Mongoid::Timestamps
#TODO put the two methods at include Mongoid::Serializers::Xml (or something alike)
# Fields
field :app_key, :type => String
field :level, :type => String, :default => 'INFO'
<?xml version="1.0" encoding="UTF-8"?>
<LogEntry>
<internal_mongo_document_id>4bbc50ce9ebea401a3000006</internal_mongo_document_id>
<internal_mongo_document_type>LogEntry</internal_mongo_document_type>
<created_at type="Time">2010-04-07 10:30:54 +0100</created_at>
<updated_at type="Time">2010-04-08 00:08:09 +0100</updated_at>
<app_key type="String">oi</app_key>
<level type="String">INFO</level>
<event_id type="String"></event_id>
require 'active_record/transitions.rb'
class Forum < ActiveRecord::Base
include ActiveRecord::Transitions
acts_as_nested_set
# Associations
has_many :posts
# Validations
@DBA
DBA / gist:465562
Created July 6, 2010 15:58
Rails.configuration
(rdb:4) pp Rails.configuration
#<Rails::Application::Configuration:0x00000100920e90
@allow_concurrency=false,
@cache_classes=false,
@cache_store=
[:file_store,
"/Users/dba/work/gnomeslab.com/programming/oauth2-ruby-server-rails-example/tmp/cache/"],
@consider_all_requests_local=true,
@dependency_loading=true,
@encoding="utf-8",
module ActiveRecordAttributesEquality
def self.included(klass)
klass.class_eval do
def ==(other)
return false unless other.is_a? self.class
if self.new_record? && other.new_record?
self.attributes == other.attributes
else