Skip to content

Instantly share code, notes, and snippets.

@ForrestSutton
Last active May 1, 2019 01:22
Show Gist options
  • Save ForrestSutton/5880215 to your computer and use it in GitHub Desktop.
Save ForrestSutton/5880215 to your computer and use it in GitHub Desktop.
rails
the Hash Rocket syntax (:foo => "bar")
is deprecated in favor of the new-to-Ruby JSON-style hash (foo: "bar")
run inside project
rvm use 1.9.3-p327@rails3 --rvmrc
rails new APP -T
rails generate controller Users new --no-test-framework
rails generate model User name:string email:string --no-test-framework
rails _3.2.13_ new demo #when the sytem has rails 4 but you want rails 3.2
rails _4.2_ new demo #when the sytem has rails 5 but you want rails 4
rails _5.x.x_ new demo #when the sytem has rails 4 but you want rails 5
git push -u origin BRANCHNAME
rake db:drop
rake db:create
rake db:migrate
rake db:seed
rollback bootstrap (or other format)
rake assets:clean
$ rails new rails-bootstrap -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
heroku run rake database:add_new_transaction RAILS_ENV=production --app vertotrack
#how to acheive blocks in red and green with a status boolean field
<style>
span.status {display; block; width; 10px; height; 10px;
margin; 0.25em auto; padding; 0; border; 1px splid #000000; }
span.status.true {background: green; color: green; }
span.status.false {background: red; color: red; }
</style>
for use in production, sends error as an email
Exception_notification gem
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
time is ticking away
time = Time.now # => Thu Jan 18 06:10:17 CST 2007
time.to_formatted_s(:time) # => "06:10"
time.to_s(:time) # => "06:10"
time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
time.to_formatted_s(:number) # => "20070118061017"
time.to_formatted_s(:short) # => "18 Jan 06:10"
time.to_formatted_s(:long) # => "January 18, 2007 06:10"
time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
##instance variable
class Item
def initialize(item_name, quantity)
@item_name = item_name
@quantity = quantity
end
def front
@front
end
#IS THE SAME AS
attr_reader :front
def front = front
@front = front
end
#IS THE SAME AS
attr_writer :front (put at top )
attr_accessor is same as attr_writer, attr_reader
####SYMBOL
module One
class Fred
end
$f1 = :Fred
end
module Two
Fred = 1
$f2 = :Fred
end
def Fred()
end
$f3 = :Fred
$f1.object_id #=> 2514190
$f2.object_id #=> 2514190
$f3.object_id #=> 2514190
! bang method shuffle(temp) shuffle! permanant chagne
! bang method make permanate modifier
@cards.each(&:play)
wrap in a method
method Flashcards
class Cards
call like Flashcards::Cards.new
avoid name collisions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment