Note: Overview of creating a new rails application, point out comparisions to sinatra as you go
- (http://guides.rubyonrails.org/getting_started.html)[http://guides.rubyonrails.org/getting_started.html]
rails
command linerails new
options
$ rails new blog -d foo
- databases - prefer
postgresql
$ rails new blog -d postgresql -T
$ cd blog
$ tree -d
- Lots of stuff!
- Find correct version: (http://guides.rubyonrails.org/)[http://guides.rubyonrails.org/]
$ rails s
OOPS :) We need to do a little more
$ cat Rakefile
$ rake -T
$ rake db:create
$ rails s
$ open http://localhost:3000/
- TADA! - (Hopefully)
$ cat config/routes.rb
$ rake routes
$ rails generate model Article title body:text
$ rake db:migrate
$ rails console
(orrails c
)$ rails db
- can fire up psql> Article.create!(:title => 'Hello World', :body => 'The answer is 42')
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'sredirect
$ rails s
$ open http://localhost:3000/articles/index
$ rake routes
- ERB the same as we did in Sinatra.
- Edit the controller and view to show the article created in the console
- Review Routing Docs - http://guides.rubyonrails.org/routing.html
- View Helpers
link_to
- Review layouts
- Add CSS in the assets folder
- RSpec