Permalink
Browse files

Re-do Getting Started application with Rails 4.

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...
1 parent 51b9def commit 2214237c3950445208635a332d520d6aa530c1de @steveklabnik steveklabnik committed Jan 22, 2013
Showing with 404 additions and 301 deletions.
  1. +16 −0 guides/code/getting_started/.gitignore
  2. +12 −12 guides/code/getting_started/Gemfile
  3. +150 −0 guides/code/getting_started/Gemfile.lock
  4. +3 −3 guides/code/getting_started/README.rdoc
  5. +0 −1 guides/code/getting_started/Rakefile
  6. +1 −0 guides/code/getting_started/app/assets/javascripts/application.js
  7. +3 −0 guides/code/getting_started/app/assets/javascripts/comments.js.coffee
  8. +3 −0 guides/code/getting_started/app/assets/javascripts/posts.js.coffee
  9. +3 −0 guides/code/getting_started/app/assets/javascripts/welcome.js.coffee
  10. +1 −1 guides/code/getting_started/app/assets/stylesheets/application.css
  11. +3 −0 guides/code/getting_started/app/assets/stylesheets/comments.css.scss
  12. +3 −0 guides/code/getting_started/app/assets/stylesheets/posts.css.scss
  13. +3 −0 guides/code/getting_started/app/assets/stylesheets/welcome.css.scss
  14. +3 −1 guides/code/getting_started/app/controllers/application_controller.rb
  15. +3 −3 guides/code/getting_started/app/controllers/comments_controller.rb
  16. 0 guides/code/getting_started/app/{mailers/.gitkeep → controllers/concerns/.keep}
  17. +17 −17 guides/code/getting_started/app/controllers/posts_controller.rb
  18. 0 guides/code/getting_started/app/{models/.gitkeep → mailers/.keep}
  19. 0 guides/code/getting_started/{lib/assets/.gitkeep → app/models/.keep}
  20. 0 guides/code/getting_started/{lib/tasks/.gitkeep → app/models/concerns/.keep}
  21. +5 −4 guides/code/getting_started/app/models/post.rb
  22. +3 −3 guides/code/getting_started/app/views/comments/_comment.html.erb
  23. +2 −2 guides/code/getting_started/app/views/layouts/application.html.erb
  24. +14 −12 guides/code/getting_started/app/views/posts/_form.html.erb
  25. +4 −4 guides/code/getting_started/app/views/posts/edit.html.erb
  26. +6 −8 guides/code/getting_started/app/views/posts/index.html.erb
  27. +3 −3 guides/code/getting_started/app/views/posts/new.html.erb
  28. +3 −3 guides/code/getting_started/app/views/posts/show.html.erb
  29. +2 −1 guides/code/getting_started/app/views/welcome/index.html.erb
  30. +4 −0 guides/code/getting_started/bin/bundle
  31. +4 −0 guides/code/getting_started/bin/rails
  32. +4 −0 guides/code/getting_started/bin/rake
  33. +2 −37 guides/code/getting_started/config/application.rb
  34. +2 −2 guides/code/getting_started/config/environment.rb
  35. +7 −7 guides/code/getting_started/config/environments/development.rb
  36. +28 −11 guides/code/getting_started/config/environments/production.rb
  37. +7 −5 guides/code/getting_started/config/environments/test.rb
  38. +4 −0 guides/code/getting_started/config/initializers/filter_parameter_logging.rb
  39. +6 −5 guides/code/getting_started/config/initializers/inflections.rb
  40. +9 −0 guides/code/getting_started/config/initializers/locale.rb
  41. +5 −2 guides/code/getting_started/config/initializers/secret_token.rb
  42. +1 −1 guides/code/getting_started/config/initializers/session_store.rb
  43. +6 −6 guides/code/getting_started/config/initializers/wrap_parameters.rb
  44. +20 −2 guides/code/getting_started/config/locales/en.yml
  45. +2 −58 guides/code/getting_started/config/routes.rb
  46. 0 ...code/getting_started/db/migrate/{20120420083127_create_posts.rb → 20130122042648_create_posts.rb}
  47. +1 −2 ...etting_started/db/migrate/{20110901012815_create_comments.rb → 20130122045842_create_comments.rb}
  48. +9 −18 guides/code/getting_started/db/schema.rb
  49. 0 guides/code/getting_started/{test/fixtures/.gitkeep → lib/assets/.keep}
  50. 0 guides/code/getting_started/{test/functional/.gitkeep → lib/tasks/.keep}
  51. 0 guides/code/getting_started/{test/integration/.gitkeep → log/.keep}
  52. +2 −1 guides/code/getting_started/public/404.html
  53. +1 −1 guides/code/getting_started/public/422.html
  54. +2 −1 guides/code/getting_started/public/500.html
  55. +0 −6 guides/code/getting_started/script/rails
  56. 0 guides/code/getting_started/test/{unit/.gitkeep → controllers/.keep}
  57. 0 guides/code/getting_started/test/{functional → controllers}/comments_controller_test.rb
  58. +1 −1 guides/code/getting_started/test/{unit/tag_test.rb → controllers/posts_controller_test.rb}
  59. +1 −0 guides/code/getting_started/test/{functional → controllers}/welcome_controller_test.rb
  60. 0 guides/code/getting_started/{vendor/plugins/.gitkeep → test/fixtures/.keep}
  61. +3 −3 guides/code/getting_started/test/fixtures/comments.yml
  62. +1 −1 guides/code/getting_started/test/fixtures/posts.yml
  63. +0 −49 guides/code/getting_started/test/functional/posts_controller_test.rb
  64. 0 guides/code/getting_started/test/helpers/.keep
  65. 0 guides/code/getting_started/test/{unit → }/helpers/comments_helper_test.rb
  66. 0 guides/code/getting_started/test/{unit → }/helpers/posts_helper_test.rb
  67. +4 −0 guides/code/getting_started/test/helpers/welcome_helper_test.rb
  68. 0 guides/code/getting_started/test/integration/.keep
  69. 0 guides/code/getting_started/test/mailers/.keep
  70. 0 guides/code/getting_started/test/models/.keep
  71. 0 guides/code/getting_started/test/{unit → models}/comment_test.rb
  72. 0 guides/code/getting_started/test/{unit → models}/post_test.rb
  73. +2 −0 guides/code/getting_started/test/test_helper.rb
  74. +0 −4 guides/code/getting_started/test/unit/helpers/home_helper_test.rb
  75. 0 guides/code/getting_started/vendor/assets/javascripts/.keep
  76. 0 guides/code/getting_started/vendor/assets/stylesheets/.keep
@@ -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
@@ -1,38 +1,38 @@
source 'https://rubygems.org'
-gem 'rails', '3.2.3'
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'rails', '4.0.0'
gem 'sqlite3'
-
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sass-rails', '~> 3.2.3'
- gem 'coffee-rails', '~> 3.2.1'
+ gem 'sprockets-rails'
+ gem 'sass-rails'
+ gem 'coffee-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
- # gem 'therubyracer', :platform => :ruby
+ # gem 'therubyracer', platforms: :ruby
gem 'uglifier', '>= 1.0.3'
end
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
# gem 'bcrypt-ruby', '~> 3.0.0'
-# To use Jbuilder templates for JSON
-# gem 'jbuilder'
-
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
-# gem 'capistrano'
+# gem 'capistrano', group: :development
# To use debugger
# gem 'debugger'
@@ -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)
@@ -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
-a different markup language.
+
+Please feel free to use a different markup language if you do not plan to run
+<tt>rake doc:app</tt>.
@@ -1,4 +1,3 @@
-#!/usr/bin/env 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.
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require turbolinks
//= require_tree .
@@ -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/
@@ -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/
@@ -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/
@@ -10,4 +10,4 @@
*
*= require_self
*= require_tree .
-*/
+ */
@@ -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/
@@ -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/
@@ -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/
@@ -1,3 +1,5 @@
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
@@ -1,9 +1,10 @@
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
@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)
end
@@ -13,5 +14,4 @@ def destroy
@comment.destroy
redirect_to post_path(@post)
end
-
end
@@ -1,7 +1,7 @@
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
@posts = Post.all
end
@@ -10,38 +10,38 @@ def show
@post = Post.find(params[:id])
end
- def new
- @post = Post.new
+ def edit
+ @post = Post.find(params[:id])
end
- def create
- @post = Post.new(params[:post])
+ def update
+ @post = Post.find(params[:id])
- if @post.save
- redirect_to :action => :show, :id => @post.id
+ if @post.update(params[:post].permit(:title, :text))
+ redirect_to action: :show, id: @post.id
else
- render 'new'
+ render 'edit'
end
end
- def edit
- @post = Post.find(params[:id])
+ def new
+ @post = Post.new
end
- def update
- @post = Post.find(params[:id])
+ def create
+ @post = Post.new(params[:post].permit(:title, :text))
- if @post.update(params[:post])
- redirect_to :action => :show, :id => @post.id
+ if @post.save
+ redirect_to action: :show, id: @post.id
else
- render 'edit'
+ render 'new'
end
end
def destroy
@post = Post.find(params[:id])
@post.destroy
- redirect_to :action => :index
+ redirect_to action: :index
end
end
@@ -1,6 +1,7 @@
class Post < ActiveRecord::Base
- validates :title, :presence => true,
- :length => { :minimum => 5 }
-
- has_many :comments, :dependent => :destroy
+ has_many :comments, dependent: :destroy
+
+ validates :title,
+ presence: true,
+ length: { minimum: 5 }
end
@@ -2,14 +2,14 @@
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
-
+
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.post, comment],
- :method => :delete,
- :data => { :confirm => 'Are you sure?' } %>
+ method: :delete,
+ data: { confirm: 'Are you sure?' } %>
</p>
Oops, something went wrong.

1 comment on commit 2214237

good job

Please sign in to comment.