🌱 Big Nerd Ranch - Ruby on the Server

These are rough notes taken during my bootcamp with Big Nerd Ranch on 2015-11-30 taught by Jordan Killpack.

Make chruby see new ruby installs source /usr/local/share/chruby/chruby.sh

rack

.ru == "rack up" rack application

http://rack.github.io

sinatra

build on rack

object relational mapping not raw sql

data_mapper

PUT = when sending full resource PATCH = when sending a partial resource

How to set env vars on Heroku https://devcenter.heroku.com/articles/config-vars

Can also be done in the dashboard > Settings for the app

How to view all ENV vars?

$ ENV

How to set an ENV var

$ export NAME_OF_VAR='foobar'

How to unset anE ENV var

$ unset NAME_OF_VAR

Rails - 2015-11-30 15.54.47

ActiveRecord == object relational mapping in Rails

http://guides.rubyonrails.org/active_record_querying.html

Rails commands

http://guides.rubyonrails.org/command_line.html

Run migrations bin/rails db:migrate

Rollback last migration bin/rails db:rollback

2015-12-01 09.30.51

View table schema

psql
\c coffee_reviews_development
\d coffee_beans

View all tasks bin/rake -T

rake db:drop rake db:create rake db:schema:load rake db:migrate

controllers

controllers should be 5-7 lines get something do something with it redirect to view

request obj http://guides.rubyonrails.org/action_controller_overview.html#the-request-object

spoof ip address curl --header "X-Forwarded-For: 1.2.3.4" "http://www.foobar.com"

auth

gem devise

security

what traffic sudo tcpdump -i lo0 -A

http://api.rubyonrails.org

routes

In routes.rb

resources :recipes

can be nested

View all routes ‘bin/rake routes’

Whitelist.pluck(:ip) from console this will return array of values in :ip

JSON API 2015-12-03 09.10.56

rails 4.2 responders gem needed for responds_with

may need jbuilder gem for json template apis

can use dedicated serialize object

jsonapi_rescources gem new neat thing

Auth

authentication = you are who you say you are authorizatoin = allow someone to do something

gem devise for authentication gem pundent for policies

use ruby profilers like new relic to see if things are effecient

Privilege.permissions.map { |p, _| [p.humanize, p] }

_ drops the second argument

Email

gem install mailcatcher

mailcatcher

http://mailcatcher.me

background tasks

active job

sidekiq

Polymorphic

no foreign keys

don’t name a column type special think in active record it will break shit

bin/rails g scaffold

rails new nerd_news -d postgresql

rm lines from database.yml in prod

bin/rake db:create:all

copy vender and assets from last project

add shit to application.css and .js

add gem ‘devise’ && bundle

destroy everything rake db:drop db:create db:migrate

irb(main):005:0> user = User.first
  User Load (7.3ms)  SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 1, email: "brandonstephens@me.com", encrypted_password: "$2a$10$.RM1gAHXSKV3vYFa5o8JluimYHAJNOt8wNomQSa2Ndt...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-12-03 22:31:44", last_sign_in_at: "2015-12-03 22:31:44", current_sign_in_ip: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, last_sign_in_ip: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, created_at: "2015-12-03 22:31:44", updated_at: "2015-12-03 22:31:44">
irb(main):006:0> Post.update_all(user_id: user.id)
  SQL (14.6ms)  UPDATE "posts" SET "user_id" = 1
=> 4

Skipped ch 26 querying

gem factory girl inserts stuff to database2

Questions

docbook used to make nerd ranch books

Made by Brandon . If you find this project useful you can donate.