This file contains hidden or 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
| field :name | |
| accessible | |
| validates :presence do | |
| message "please provide a name" | |
| end | |
| end | |
| field :email | |
| accessible | |
| validates :format do |
This file contains hidden or 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
| def do_bulk_creation # Controller action called from request | |
| prize = Prize.find_by_id(params[:code][:prize_id]) | |
| codes = params[:code][:codes].split("\r\n").each{ |c| c.strip } | |
| if bulk_creation_valid?(prize, codes) | |
| perform_bulk_creation(prize, codes) | |
| else | |
| set_bulk_creation_error(prize, codes) | |
| @bulk = Code.new(params[:code]) | |
| render :action => :bulk_create | |
| end |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; |