Skip to content

Instantly share code, notes, and snippets.

@37celsius
Last active August 29, 2015 14:19
Show Gist options
  • Save 37celsius/bac87909d5463a893931 to your computer and use it in GitHub Desktop.
Save 37celsius/bac87909d5463a893931 to your computer and use it in GitHub Desktop.
GA WDI 0702 Class note

Rails

Quick Demo

# FIRST STEP, Create the new app with all the folders
rails new twitter_app --database=postgresql

# SECOND STEP, Create database
rake db:create

# THIRD STEP, Create some function/ methods
rails generate scaffold tweet content:string

# FOURTH STEP, Connect to the DB
rake db:migrate

# FIFTH STEP, run the app in browser
rails server

Rails

Creating GoodFoodHunting App using Rails

# FIRST STEP, Create the new app with all the folders minus test folder
rails new twitter_app --database=postgresql -T

# SECOND STEP, Create database
rake db:create

# THIRD STEP, Check if everything alright by looking the app in browser
rails server

# FOURTH STEP, We wnt to create a model database FILE, model always singular
# We also want to generate the columns for title as a string image_url as a string
rails generate model Dish title:string image_url:string

# FIFTH STEP, Now we want to execute the database FILE that we created in FOURTH STEP
# Also this as version control, ALWAYS check the file in db/ migrate/ look at te .rb file
rake db:migrate

# SIXTH STEP, Setting up the routes, the file is inside config/routes.rb
# 'pages (is controller) # index(is an action)'
# basically telling this route '/' go to pages controller go to index
get '/' => 'pages#index'

# SEVENTH STEP, Create the PAGES Controller inside the folder app/ controllers
# Create a new file pages_controller.rb

# EIGHT STEP, inside that pages_controller.rb we create a link for the index page
def index
end

# NINTH STEP, Create a folder that the same as the controller name
# which is PAGES in this case inside the views folder
app/ views/ (create new folder pages)

# TENTH STEP, Create an html file that we call in the SIXTH STEP
# inside the pages folder
index.html.erb

### INTERMEZZO, YOU CAN CHECK THE INFO BY TYPING RAILS/INFO IN THE BROWSER
### IE, http://localhost:3000/rails/info/routes

### WHEN we using form we have to do Authenticity TOKEN
### CSRF = CROSS-SITE REQUEST FORGERY 
### Need to put the form_authenticity_token inside the form 
### IE, 
<form>
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment