an app of our own

Template slide

MVC REVIEW


  • Trace the URL "/microposts/1" through the MVC architecture

RAILS REview


  • What is the command to create a new rails application?

Rails Review

rails new <project_name>

  • How do we open that project up in Sublime?

Rails Review

rails new <project_name>

  • How do we start a rails server?

Rails Review


rails new <project_name>
rails s

  • How do we view our rails project in the browser?

Rails review


  • Let's get our new project on Github:

git init
git add .
git commit -m "Initial Commit"
go to github.com and create a new repo
git add remote <git_repo_url>
git push -u origin master

SCAFFOLDING


  • What does rails scaffold make?

SCAFFOLDING


  • migration
  • model
  • controller
  • views
  • routes

RAILS GENERATE


  • rails scaffold is just one way you can make your rails app
  • you can use rails generate to make each part on its own

Rails Generate


  • GOAL: setup our rails project to have 2 static pages (home and about)
  • Static pages do NOT need to use the database
  • What do we need to make?

RAils GENERATE


  • routes
  • controller
  • views

We DON'T need:
  • model

RAILS GENERATE


To make just a controller with routes and views we can use this  command:

rails generate controller StaticPages home about


rails generate - rails make this!

controller - make a controller with no model

StaticPages - the name of the controller

home, about - the views and routes to make

RAILS GENERATE


What if you mess up a rails generate command?

rails destroy StaticPages controller home about contact

Rails generate


What did we get?

routes.rb -> routes for each page

static_pages_controller.rb -> actions for each page

app/views/static_pages -> html.erb for each page

Let's commit


  • git add . 
  • git commit -m "Add a StaticPages controller"

Rails views


A new approach to 

 Layout:  application.html.erb 

put all your doctype and head info here
headers, navs, and footers too!
=yield is where all your other pages will be rendered

Rails views


Views also let you create partials that can render individual chunks of html over and over 

THE BOOTSTRAP GEM


  • Open your Gemfile
  • Add the line:

gem 'bootstrap-sass', '2.1'

  • go to terminal and type bundle install

a custom css file


  • Make a file called:

custom.css.scss

  • Put it in the folder:

app/assets/stylesheets

Add bootstrap to your file


  • In your custom.css.scss file write

@import "bootstrap";

Add your file to the layout


  • Go to the file 
app/views/layout/application.html.erb

  • and type
<%  stylesheet_link_tag "application", :media=> "all  %>

Let's Commit


  • git add .
  • git commit -m "integrate Bootstrap"

Moving your files


HTML
  • Look at your homepage
  • Decide: what part of the html is repeating content, and which is the main content
  • cut and paste the repeating content into application.html.erb
  • cut and paste the content into home.html.erb

CSS
  • cut and paste the contents of your custom CSS file into custom.scss.css

linking things up


  • we can make links with ruby
  • to write embedded ruby(ERB) create a tag like this

<% %>

  • to link something we type
<%= link_to path_name %>

we can find the path name by doing rake routes

making a new static page


  • first create a .html.erb file
  • next, create an action in your controller with the name of that file
  • then put a route in routes.rb

EXAMPLE: a projects page
  • create app/views/static_pages/projects.html.erb
  • in static_pages_controller.rb write
        def projects
        end
  • in routes.rb write get "static_pages/projects"

an app of our own

By ag_dubs

an app of our own

  • 371