Skip to content

Commit

Permalink
Re-do Getting Started application with Rails 4.
Browse files Browse the repository at this point in the history
The sample application with the Getting Started Guide was very out of
date. I've re-done it on edge (as of 51b9def) so it should
be good to go with Rails 4. It's also in synch with what the guide
actually says.
  • Loading branch information
steveklabnik committed Jan 22, 2013
1 parent 51b9def commit 2214237
Show file tree
Hide file tree
Showing 76 changed files with 404 additions and 301 deletions.
16 changes: 16 additions & 0 deletions guides/code/getting_started/.gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
24 changes: 12 additions & 12 deletions guides/code/getting_started/Gemfile
Original file line number Original file line Diff line number Diff line change
@@ -1,38 +1,38 @@
source 'https://rubygems.org' source 'https://rubygems.org'


gem 'rails', '3.2.3' gem 'rails', '4.0.0'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'


gem 'sqlite3' gem 'sqlite3'



# Gems used only for assets and not required # Gems used only for assets and not required
# in production environments by default. # in production environments by default.
group :assets do group :assets do
gem 'sass-rails', '~> 3.2.3' gem 'sprockets-rails'
gem 'coffee-rails', '~> 3.2.1' gem 'sass-rails'
gem 'coffee-rails'


# See https://github.com/sstephenson/execjs#readme for more supported runtimes # See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby # gem 'therubyracer', platforms: :ruby


gem 'uglifier', '>= 1.0.3' gem 'uglifier', '>= 1.0.3'
end end


gem 'jquery-rails' gem 'jquery-rails'


# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'

# To use ActiveModel has_secure_password # To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0' # gem 'bcrypt-ruby', '~> 3.0.0'


# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server # Use unicorn as the app server
# gem 'unicorn' # gem 'unicorn'


# Deploy with Capistrano # Deploy with Capistrano
# gem 'capistrano' # gem 'capistrano', group: :development


# To use debugger # To use debugger
# gem 'debugger' # gem 'debugger'
150 changes: 150 additions & 0 deletions guides/code/getting_started/Gemfile.lock
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,150 @@
GIT
remote: git://github.com/rails/activerecord-deprecated_finders.git
revision: 2e7b35d7948cefb2bba96438873d7f7bb1961a03
specs:
activerecord-deprecated_finders (0.0.2)

GIT
remote: git://github.com/rails/arel.git
revision: 38d0a222e275d917a2c1d093b24457bafb600a00
specs:
arel (3.0.2.20120819075748)

GIT
remote: git://github.com/rails/coffee-rails.git
revision: 052634e6d02d4800d7b021201cc8d5829775b3cd
specs:
coffee-rails (4.0.0.beta)
coffee-script (>= 2.2.0)
railties (>= 4.0.0.beta, < 5.0)

GIT
remote: git://github.com/rails/sass-rails.git
revision: ae8138a89cac397c0df903dd533e2862902ce8f5
specs:
sass-rails (4.0.0.beta)
railties (>= 4.0.0.beta, < 5.0)
sass (>= 3.1.10)
sprockets-rails (~> 2.0.0.rc0)
tilt (~> 1.3)

GIT
remote: git://github.com/rails/sprockets-rails.git
revision: 09917104fdb42245fe369612a7b0e3d77e1ba763
specs:
sprockets-rails (2.0.0.rc1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)

PATH
remote: /Users/steve/src/rails
specs:
actionmailer (4.0.0.beta)
actionpack (= 4.0.0.beta)
mail (~> 2.5.3)
actionpack (4.0.0.beta)
activesupport (= 4.0.0.beta)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.4.3)
rack-test (~> 0.6.1)
activemodel (4.0.0.beta)
activesupport (= 4.0.0.beta)
builder (~> 3.1.0)
activerecord (4.0.0.beta)
activemodel (= 4.0.0.beta)
activerecord-deprecated_finders (= 0.0.2)
activesupport (= 4.0.0.beta)
arel (~> 3.0.2)
activesupport (4.0.0.beta)
i18n (~> 0.6)
minitest (~> 4.1)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.33)
rails (4.0.0.beta)
actionmailer (= 4.0.0.beta)
actionpack (= 4.0.0.beta)
activerecord (= 4.0.0.beta)
activesupport (= 4.0.0.beta)
bundler (>= 1.2.2, < 2.0)
railties (= 4.0.0.beta)
sprockets-rails (~> 2.0.0.rc1)
railties (4.0.0.beta)
actionpack (= 4.0.0.beta)
activesupport (= 4.0.0.beta)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.15.4, < 2.0)

GEM
remote: https://rubygems.org/
specs:
atomic (1.0.1)
builder (3.1.4)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.4.0)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.1)
jbuilder (1.0.2)
activesupport (>= 3.0.0)
jquery-rails (2.2.0)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.6)
mail (2.5.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
minitest (4.4.0)
multi_json (1.5.0)
polyglot (0.3.3)
rack (1.4.4)
rack-test (0.6.2)
rack (>= 1.0)
rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
sass (3.2.5)
sprockets (2.8.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
thor (0.16.0)
thread_safe (0.1.0)
atomic
tilt (1.3.3)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.0.0)
coffee-rails
tzinfo (0.3.35)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)

PLATFORMS
ruby

DEPENDENCIES
activerecord-deprecated_finders!
arel!
coffee-rails!
jbuilder (~> 1.0.1)
jquery-rails
rails!
sass-rails!
sprockets-rails!
sqlite3
turbolinks
uglifier (>= 1.0.3)
6 changes: 3 additions & 3 deletions guides/code/getting_started/README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Things you may want to cover:


* ... * ...


If you plan to generate application documentation with `rake doc:app` this file
is expected to be `README.rdoc`, otherwise please feel free to rename it and use Please feel free to use a different markup language if you do not plan to run
a different markup language. <tt>rake doc:app</tt>.
1 change: 0 additions & 1 deletion guides/code/getting_started/Rakefile
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake, # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
// //
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks
//= require_tree . //= require_tree .
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* *
*= require_self *= require_self
*= require_tree . *= require_tree .
*/ */
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end end
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,10 @@
class CommentsController < ApplicationController class CommentsController < ApplicationController
http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy


  http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy

def create def create
@post = Post.find(params[:post_id]) @post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment]) @comment = @post.comments.create(params[:comment].permit(:commenter, :body))
redirect_to post_path(@post) redirect_to post_path(@post)
end end


Expand All @@ -13,5 +14,4 @@ def destroy
@comment.destroy @comment.destroy
redirect_to post_path(@post) redirect_to post_path(@post)
end end

end end
34 changes: 17 additions & 17 deletions guides/code/getting_started/app/controllers/posts_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
class PostsController < ApplicationController class PostsController < ApplicationController


http_basic_authenticate_with :name => "dhh", :password => "secret", :except => [:index, :show]   http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]

def index def index
@posts = Post.all @posts = Post.all
end end
Expand All @@ -10,38 +10,38 @@ def show
@post = Post.find(params[:id]) @post = Post.find(params[:id])
end end


def new def edit
@post = Post.new @post = Post.find(params[:id])
end end


def create def update
@post = Post.new(params[:post]) @post = Post.find(params[:id])


if @post.save if @post.update(params[:post].permit(:title, :text))
redirect_to :action => :show, :id => @post.id redirect_to action: :show, id: @post.id
else else
render 'new' render 'edit'
end end
end end


def edit def new
@post = Post.find(params[:id]) @post = Post.new
end end


def update def create
@post = Post.find(params[:id]) @post = Post.new(params[:post].permit(:title, :text))


if @post.update(params[:post]) if @post.save
redirect_to :action => :show, :id => @post.id redirect_to action: :show, id: @post.id
else else
render 'edit' render 'new'
end end
end end


def destroy def destroy
@post = Post.find(params[:id]) @post = Post.find(params[:id])
@post.destroy @post.destroy


redirect_to :action => :index redirect_to action: :index
end end
end end
9 changes: 5 additions & 4 deletions guides/code/getting_started/app/models/post.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
class Post < ActiveRecord::Base class Post < ActiveRecord::Base
validates :title, :presence => true, has_many :comments, dependent: :destroy
:length => { :minimum => 5 }

validates :title,
has_many :comments, :dependent => :destroy presence: true,
length: { minimum: 5 }
end end
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<strong>Commenter:</strong> <strong>Commenter:</strong>
<%= comment.commenter %> <%= comment.commenter %>
</p> </p>

<p> <p>
<strong>Comment:</strong> <strong>Comment:</strong>
<%= comment.body %> <%= comment.body %>
</p> </p>


<p> <p>
<%= link_to 'Destroy Comment', [comment.post, comment], <%= link_to 'Destroy Comment', [comment.post, comment],
:method => :delete, method: :delete,
:data => { :confirm => 'Are you sure?' } %> data: { confirm: 'Are you sure?' } %>
</p> </p>
Loading

1 comment on commit 2214237

@railscast
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

Please sign in to comment.