mac install ruby


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
brew install rbenv ruby-build
# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
# Install Ruby
rbenv install 2.4.1
rbenv global 2.4.1
ruby -v
# you should install the Command Line tools as they aren't installed by default (xcode)
xcode-select --install
gem install rails -v 5.1.3
rbenv rehash
rails -v
# create new application
rails new blog
# if webpacker is not installed
brew install yarn
rails webpacker:install
# run server
rails server

server


1
2
# start default web server: puma
rails server

drop & clear table

1
2
3
4
5
6
7
rails console
ActiveRecord::Migration.drop_table(:users)
# where users is the table name. And done, worked for me!
##clear table
rails db:purge

destroy model

1
2
3
rails destroy model student
# where student is the model

generate model

1
2
3
4
5
6
7
8
9
10
11
12
13
rails generate model student \
uin:integer first_name:string middle_name:string last_name:string \
level: integer \
email:string \
phone: string \
assigned: boolean \
advisor_email: string \
can_ta: boolean \
can_grader: boolean \
can_sgrader: boolean \
perferences: string \
date_enrolled: date \
last_modified: timestamp

rbenv usage

1
2
3
4
5
6
7
8
9
10
11
12
# list all installed ruby
rbenv versions
# list all available versions
rbenv install -l
#install ruby
rbenv install 2.0.0-p247
#use local
rbenv local 2.0.0-p247
rbenv rehash

heroku

1
heroku run rake db:migrate --app morning-reef-98714