Skip to content

Instantly share code, notes, and snippets.

@chyld
Created June 17, 2012 23:08
Show Gist options
  • Save chyld/2946012 to your computer and use it in GitHub Desktop.
Save chyld/2946012 to your computer and use it in GitHub Desktop.
Rails, Pry, Pow notes
rails new experimental
rm public/index.html
pry -r ./config/environment
rails generate scaffold Product name:string description:text price:decimal
in application.js (for example)
*** require_tree . # loads all files recursively
*** require_directory . # loads only files in the current directory
Rails.application.config.assets.paths # search path for assets
other.js.coffee.erb # preprocessors - erb is 1st, coffee is 2nd and final output is js
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
http://guides.rubyonrails.org/active_record_validations_callbacks.html
valid? or invalid?
object.errors
create, save, update, update_attributes
validates :name, :presence => true
validates :name, :acceptance => { :accept => 'chyld' }
validates :is_good, :acceptance => { :accept => true }
attr_accessible :description, :name, :name_confirmation, :price
validates :email, :confirmation => true
validates :name, :length => { :minimum => 2 }
validates :bio, :length => { :maximum => 500 }
validates :password, :length => { :in => 6..20 }
validates :registration_number, :length => { :is => 6 }
validates :points, :numericality => true
validates :games_played, :numericality => { :only_integer => true }
# also options for greater than, less than, odd, even, etc.
validates :email, :uniqueness => true # may need to also create database unique constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment