- Always Read the Rails Guides for Overviews
- Search for solutions on google
- Really only read the API Docs if things get really gnarly
$ rails new --help
Note To (Instructor/Self): Remove ~/.railsrc before Demo
$ cat ~/.railsrc
-d=postgresql
-T
-B
--skip-spring
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)
Pro Tip: Rails Console
$ rails c
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
- ERB the same as we did in Sinatra.
- What is Implicit Render?
- View Helpers
link_to
,form_for
$ cat config/routes.rb
$ rake routes
_path and _url
helpers used in views and redirects
$ rails c
> app.pizzas_url
=> "http://www.example.com/pizzas"
> app.edit_pizza_url(1)
=> "http://www.example.com/pizzas/1/edit"
$ 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')
resources :articles
$ rails s
$ open http://localhost:3000/articles/index
- Review Routing Docs - http://guides.rubyonrails.org/routing.html
- View Helpers
link_to
,form_for
- Review views / layouts
- Add CSS in the assets folder *
- RSpec
- What is scaffolding?
rails g scaffold pizzas