Rails

https://agilewarrior.wordpress.com/2014/10/11/rvm-management-workflow/

Common commands
$ rails s
$ rake test
$ ruby test/test_meme.rb
$ git push staging
$ git push prod

Rebuild db
$ rake db:drop
$ rake db:migrate
$ rake db:migrate:reset
$ rake db:seed
$ rake db:test:prepare
$ rake db:reset
$ rake db:populate
$ rake db:test:prepare

Figure out heroku database instance
$ heroku apps
$ heroku addons –app hidden-xxxx-xxxx | grep POSTGRES
$ heroku-postgresql:dev HEROKU_POSTGRESQL_ORANGE

Generators

https://agilewarrior.wordpress.com/2014/10/12/rails-generators-cheat-sheet/

$ rails new app
$ rails g scaffold Foo foo_string:string foo_text:text foo_integer:integer foo_float:float foo_decimal:decimal foo_timestamp:timestamp foo_time:time foo_date:date foo_binary:binary foo_boolean:boolean

$ rake db:migrate

Types: :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean.

Migrations

Rename database column

$ rails g migration RenameAwsVideoColumn
class FixColumnName < ActiveRecord::Migration
  def change
    rename_column :table_name, :old_column, :new_column
  end
end

Stand alone migration

$ rails generate migration AddPartNumberToProducts

Add/Remove column migration

$ rails generate migration AddBuyerIdToTransactions part_number:string buyer_id:integer

class AddBuyerIdToTransactions < ActiveRecord::Migration
def change
add_column :transactions, :buyer_id, :integer
end
end

Console

$ rails console --sandbox

user = User.new(name: “Example User”, email: “user@example.com”,password: “foobar”, password_confirmation: “foobar”)
user.save()
user.save(:validate => false)
user.valid?
user.errors.inspect
puts user

Misc

$ rake routes

it "foo" do
puts page.body
end
  • controller
    logger.debug “===================”

RVM

https://agilewarrior.wordpress.com/2014/10/11/rvm-management-workflow/

switch versions

$ rvm 1.9.2@rails126 ; rails --version
$ rvm 1.9.2@rails310 ; rails --version

$ rvm --default use ruby-1.9.3-p125

$ rvm --help

$ rvm use 2.0

managing old gem versions

$ gem list
$ gem cleanup rjb
$ gem uninstall rjb
$ gem uninstall rjb --version 1.1.9
$ gem install rspec -v 2.14.1
$ gem uninstall rspec

list latest version of gem

$ gem list rhc --remote --all

Testing

it "foo" do
        puts page.body
end

Controller variables

raise @episode.inspect

Diff between <%= and <=

  is a snippet of Rails code (ie starting a conditional, ending a conditional, etc)
  actually evaluates an expression and returns a value to the page

 - output the trade date to screen
 - evaluate this conditional (output nothing)

Links that help

RVM Gemset Management
Hashes & Symbols
Rails Generator Cheat Sheet
How to create user
how-to-create-static-pages-rails
how-to-model-has-two-associations-in-rails
how-to-setup-rspec-from-scratch
how-to-setup-a-new-ruby-project-with-tests
how-to-create-a-staging-environment-heroku
how-to-create-a-named-app-in-heroku
jquery-links-and-elements-not-reloading-in-rails
how-to-use-glyphicons-in-twitter-bootstrap/
how-to-add-jquery-ui-theme-to-your-rails-app
how-include-jquery-ui-in-your-rails-app/
how-to-setup-twitter-bootstrap-rails-from-scratch-rails
how-to-add-a-flash-message-to-your-rails-page
how-to-pass-variable-to-partials-in-rails
how-to-specify-controller-and-action-in-rails-form
how-to-import-heroku-postgres-locally-from-prod-rails
how-to-install-postgres-rails
how-to-setup-and-amazon-webservices-and-connect-to-from-rails
how-to-create-a-new-rails-page
rails-has_many-example

Rubymine shortcuts
Option up arrow Extend selection in preferences MAC OSX 10.5+ keyboard mapping
Generate Code (tdd new method) – option + Enter
New test – ase -> tab
Refactor this – ^T
Live Templates – Cmd J

Click to access RubyMine_ReferenceCard_Mac.pdf

http://pivotallabs.com/code-generation-in-rubymine/

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: