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
class Account < ActiveRecord::Base | |
has_many :users | |
accepts_nested_attributes_for :users | |
serialize :account #If you want to store the recurly account, you need to serialise the object | |
validates_presence_of :company, :on => :create, :message => "can't be blank" | |
# Before_create will be called once only | |
before_create :create_external_account |
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
class Foo < ActiveRecord::Base | |
after_initialize :do_stuff | |
def do_stuff | |
self.parameter = "string" if self.parameter.nil? | |
end | |
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
trussell@whopper:~/Projects/app/$ php -a | |
Interactive shell | |
php > $foo = "16.83"; | |
php > echo $foo; | |
16.83 | |
php > $bar = (float) $foo; | |
php > echo $bar; | |
16.83 | |
php > $baz = $bar * 100; |
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
class ContactController < ApplicationController | |
def new | |
@message = Message.new | |
end | |
def create | |
@message = Message.new(params[:message]) | |
if @message.valid? | |
Contact.contact(@message).deliver |
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
# Contact Mailer | |
class Contact < ActionMailer::Base | |
#default :to => "[email protected]" | |
def contact(message, sender) | |
@message = message | |
@sender = sender | |
mail( | |
:from => sender, | |
:to => "[email protected]", |
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
class CreateLoginRecords < ActiveRecord::Migration | |
def self.up | |
create_table :login_records do |t| | |
t.integer :user_id | |
t.datetime :logged_in | |
t.timestamps | |
end | |
add_index(:login_records, :user_id) | |
add_index(:login_records, :logged_in) |
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
nnoremap <f2> :bnext<CR> | |
nnoremap <f1> :bprevious<CR> | |
set wildmode=list:longest,full "pretty finding | |
set noswapfile | |
set number | |
set smartindent | |
set tabstop=8 | |
set shiftwidth=2 | |
set expandtab | |
set softtabstop=2 |
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
class ApplicationController | |
private | |
def my_filter_method(myarg, data) | |
if myarg == "file" | |
@file = File.open(myarg, data) | |
elsif myarg == "url" | |
Net::HTTP.get(myarg, data) | |
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
class MyClass | |
attr_accessor :at1, :at2, :at3 | |
def initialize | |
@at1 = "one" | |
@at2 = "two" | |
@at3 = "three" | |
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
class DataCenter < ActiveRecord::Base | |
# has configuration_type, configuration_id attributes | |
def config | |
configuration_type.constantize.find(configuration_id) | |
end | |
def config=(config) | |
configuration_type = config.class.name | |
configuration_id = config.id | |
end |
OlderNewer