Skip to content

Instantly share code, notes, and snippets.

@stujo
Created March 16, 2015 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stujo/39b22c10b46c405dbeb1 to your computer and use it in GitHub Desktop.
Save stujo/39b22c10b46c405dbeb1 to your computer and use it in GitHub Desktop.
Rails vs Sinatra

Rails vs Sinatra

Note: Overview of creating a new rails application, point out comparisions to sinatra as you go

Creating a new Rails Application

$ rails new blog -d foo
  • databases - prefer postgresql
$ rails new blog -d postgresql -T

Walkthrough Generated Files

$ cd blog
$ tree -d

Starting a Rails Application

$ rails s

OOPS :) We need to do a little more

Initializing the Database

$ cat Rakefile
$ rake -T
$ rake db:create
$ rails s
$ open http://localhost:3000/
  • TADA! - (Hopefully)

Building Your Application

Routing

  • $ cat config/routes.rb
  • $ rake routes

Models

  • $ rails generate model Article title body:text
  • $ rake db:migrate
  • $ rails console (or rails c)
  • $ rails db - can fire up psql
  • > Article.create!(:title => 'Hello World', :body => 'The answer is 42')

Controllers

  • rails g controller articles index
  • But that generates some things we don't want....
  • rails g controller articles index --no-helper --no-assets
  • redirect_to instead of Sinatra's redirect
$ rails s
$ open http://localhost:3000/articles/index

Routing Revisited

  • $ rake routes

Views

  • ERB the same as we did in Sinatra.
  • Edit the controller and view to show the article created in the console

And Go Do It!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment