railties 3.1.12 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2292 -41
- data/README.rdoc +14 -5
- data/bin/rails +7 -0
- data/guides/code/getting_started/Gemfile +27 -0
- data/guides/code/getting_started/README.rdoc +261 -0
- data/guides/code/getting_started/Rakefile +7 -0
- data/guides/code/getting_started/app/assets/images/rails.png +0 -0
- data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
- data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
- data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
- data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
- data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
- data/guides/code/getting_started/app/models/comment.rb +3 -0
- data/guides/code/getting_started/app/models/post.rb +11 -0
- data/guides/code/getting_started/app/models/tag.rb +3 -0
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
- data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
- data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
- data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
- data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
- data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
- data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
- data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
- data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
- data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
- data/guides/code/getting_started/config.ru +4 -0
- data/guides/code/getting_started/config/application.rb +53 -0
- data/guides/code/getting_started/config/boot.rb +6 -0
- data/guides/code/getting_started/config/database.yml +25 -0
- data/guides/code/getting_started/config/environment.rb +5 -0
- data/guides/code/getting_started/config/environments/development.rb +37 -0
- data/guides/code/getting_started/config/environments/production.rb +67 -0
- data/guides/code/getting_started/config/environments/test.rb +37 -0
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
- data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
- data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
- data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
- data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
- data/guides/code/getting_started/config/locales/en.yml +5 -0
- data/guides/code/getting_started/config/routes.rb +64 -0
- data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
- data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
- data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
- data/guides/code/getting_started/db/schema.rb +43 -0
- data/guides/code/getting_started/db/seeds.rb +7 -0
- data/guides/code/getting_started/doc/README_FOR_APP +2 -0
- data/guides/code/getting_started/public/404.html +26 -0
- data/guides/code/getting_started/public/422.html +26 -0
- data/guides/code/getting_started/public/500.html +26 -0
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +5 -0
- data/guides/code/getting_started/script/rails +6 -0
- data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
- data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
- data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
- data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
- data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
- data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
- data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
- data/guides/code/getting_started/test/test_helper.rb +13 -0
- data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
- data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/post_test.rb +7 -0
- data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
- data/guides/rails_guides/generator.rb +2 -1
- data/guides/source/3_0_release_notes.textile +2 -2
- data/guides/source/3_1_release_notes.textile +3 -110
- data/guides/source/action_controller_overview.textile +11 -13
- data/guides/source/action_mailer_basics.textile +7 -18
- data/guides/source/action_view_overview.textile +78 -9
- data/guides/source/active_model_basics.textile +205 -0
- data/guides/source/active_record_basics.textile +31 -31
- data/guides/source/active_record_querying.textile +288 -67
- data/guides/source/active_record_validations_callbacks.textile +69 -75
- data/guides/source/active_resource_basics.textile +48 -2
- data/guides/source/active_support_core_extensions.textile +145 -24
- data/guides/source/ajax_on_rails.textile +65 -7
- data/guides/source/api_documentation_guidelines.textile +0 -6
- data/guides/source/asset_pipeline.textile +2 -2
- data/guides/source/association_basics.textile +25 -34
- data/guides/source/caching_with_rails.textile +12 -17
- data/guides/source/command_line.textile +29 -19
- data/guides/source/configuring.textile +40 -18
- data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
- data/guides/source/debugging_rails_applications.textile +10 -21
- data/guides/source/engines.textile +618 -0
- data/guides/source/form_helpers.textile +1 -12
- data/guides/source/generators.textile +9 -11
- data/guides/source/getting_started.textile +152 -152
- data/guides/source/i18n.textile +4 -5
- data/guides/source/index.html.erb +0 -1
- data/guides/source/initialization.textile +26 -26
- data/guides/source/layouts_and_rendering.textile +97 -61
- data/guides/source/migrations.textile +380 -161
- data/guides/source/performance_testing.textile +4 -10
- data/guides/source/plugins.textile +11 -19
- data/guides/source/rails_application_templates.textile +12 -4
- data/guides/source/rails_on_rack.textile +25 -19
- data/guides/source/routing.textile +6 -13
- data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
- data/guides/source/security.textile +11 -15
- data/guides/source/testing.textile +1 -9
- data/lib/rails/application.rb +107 -42
- data/lib/rails/application/bootstrap.rb +12 -11
- data/lib/rails/application/configuration.rb +27 -21
- data/lib/rails/application/finisher.rb +40 -17
- data/lib/rails/application/route_inspector.rb +75 -0
- data/lib/rails/application/routes_reloader.rb +15 -4
- data/lib/rails/code_statistics.rb +16 -5
- data/lib/rails/commands.rb +6 -5
- data/lib/rails/commands/application.rb +8 -1
- data/lib/rails/commands/console.rb +2 -0
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +0 -2
- data/lib/rails/commands/generate.rb +3 -3
- data/lib/rails/commands/plugin.rb +161 -159
- data/lib/rails/commands/plugin_new.rb +3 -2
- data/lib/rails/commands/runner.rb +4 -0
- data/lib/rails/console/app.rb +26 -22
- data/lib/rails/console/helpers.rb +9 -5
- data/lib/rails/engine.rb +70 -34
- data/lib/rails/engine/commands.rb +39 -0
- data/lib/rails/engine/configuration.rb +1 -1
- data/lib/rails/generators.rb +3 -14
- data/lib/rails/generators/actions.rb +36 -9
- data/lib/rails/generators/app_base.rb +34 -38
- data/lib/rails/generators/base.rb +4 -4
- data/lib/rails/generators/generated_attribute.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -3
- data/lib/rails/generators/rails/app/USAGE +6 -0
- data/lib/rails/generators/rails/app/app_generator.rb +6 -2
- data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
- data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/rails/task/USAGE +9 -0
- data/lib/rails/generators/rails/task/task_generator.rb +12 -0
- data/lib/rails/generators/rails/task/templates/task.rb +8 -0
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
- data/lib/rails/paths.rb +11 -38
- data/lib/rails/rack/debugger.rb +3 -4
- data/lib/rails/rack/logger.rb +26 -12
- data/lib/rails/railtie.rb +6 -1
- data/lib/rails/railtie/configuration.rb +12 -5
- data/lib/rails/source_annotation_extractor.rb +12 -10
- data/lib/rails/tasks/documentation.rake +3 -1
- data/lib/rails/tasks/engine.rake +1 -0
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +3 -23
- data/lib/rails/test_help.rb +1 -2
- data/lib/rails/test_unit/testing.rake +8 -4
- data/lib/rails/version.rb +3 -3
- metadata +131 -61
- checksums.yaml +0 -7
- data/lib/rails/generators/rails/plugin/USAGE +0 -13
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
- data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
- data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostsControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@post = posts(:one)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get index" do
|
9
|
+
get :index
|
10
|
+
assert_response :success
|
11
|
+
assert_not_nil assigns(:posts)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should get new" do
|
15
|
+
get :new
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should create post" do
|
20
|
+
assert_difference('Post.count') do
|
21
|
+
post :create, post: @post.attributes
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_redirected_to post_path(assigns(:post))
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should show post" do
|
28
|
+
get :show, id: @post.to_param
|
29
|
+
assert_response :success
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should get edit" do
|
33
|
+
get :edit, id: @post.to_param
|
34
|
+
assert_response :success
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should update post" do
|
38
|
+
put :update, id: @post.to_param, post: @post.attributes
|
39
|
+
assert_redirected_to post_path(assigns(:post))
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should destroy post" do
|
43
|
+
assert_difference('Post.count', -1) do
|
44
|
+
delete :destroy, id: @post.to_param
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_redirected_to posts_path
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rails/performance_test_help'
|
3
|
+
|
4
|
+
class BrowsingTest < ActionDispatch::PerformanceTest
|
5
|
+
# Refer to the documentation for all available options
|
6
|
+
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
7
|
+
# :output => 'tmp/performance', :formats => [:flat] }
|
8
|
+
|
9
|
+
def test_homepage
|
10
|
+
get '/'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
@@ -137,7 +137,8 @@ module RailsGuides
|
|
137
137
|
|
138
138
|
if guide =~ /\.html\.erb$/
|
139
139
|
# Generate the special pages like the home.
|
140
|
-
|
140
|
+
# Passing a template handler in the template name is deprecated. So pass the file name without the extension.
|
141
|
+
result = view.render(:layout => 'layout', :file => $`)
|
141
142
|
else
|
142
143
|
body = File.read(File.join(source_dir, guide))
|
143
144
|
body = set_header_section(body, view)
|
@@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a +
|
|
59
59
|
|
60
60
|
h4. Upgrade Process
|
61
61
|
|
62
|
-
To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/
|
62
|
+
To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it.
|
63
63
|
|
64
64
|
Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following:
|
65
65
|
|
66
66
|
<shell>
|
67
|
-
$ ruby script/plugin install git://github.com/
|
67
|
+
$ ruby script/plugin install git://github.com/rails/rails_upgrade.git
|
68
68
|
</shell>
|
69
69
|
|
70
70
|
You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin
|
@@ -21,113 +21,6 @@ Rails 3.1 requires Ruby 1.8.7 or higher. Support for all of the previous Ruby ve
|
|
21
21
|
|
22
22
|
TIP: Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition have these fixed since release 1.8.7-2010.02 though. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x jump on 1.9.2 for smooth sailing.
|
23
23
|
|
24
|
-
h4. What to update in your apps
|
25
|
-
|
26
|
-
The following changes are meant for upgrading your application to Rails 3.1.3, the latest 3.1.x version of Rails.
|
27
|
-
|
28
|
-
h5. Gemfile
|
29
|
-
|
30
|
-
Make the following changes to your +Gemfile+.
|
31
|
-
|
32
|
-
<ruby>
|
33
|
-
gem 'rails', '= 3.1.3'
|
34
|
-
gem 'mysql2'
|
35
|
-
|
36
|
-
# Needed for the new asset pipeline
|
37
|
-
group :assets do
|
38
|
-
gem 'sass-rails', "~> 3.1.5"
|
39
|
-
gem 'coffee-rails', "~> 3.1.1"
|
40
|
-
gem 'uglifier', ">= 1.0.3"
|
41
|
-
end
|
42
|
-
|
43
|
-
# jQuery is the default JavaScript library in Rails 3.1
|
44
|
-
gem 'jquery-rails'
|
45
|
-
</ruby>
|
46
|
-
|
47
|
-
h5. config/application.rb
|
48
|
-
|
49
|
-
* The asset pipeline requires the following additions:
|
50
|
-
|
51
|
-
<ruby>
|
52
|
-
config.assets.enabled = true
|
53
|
-
config.assets.version = '1.0'
|
54
|
-
</ruby>
|
55
|
-
|
56
|
-
* If your application is using the "/assets" route for a resource you may want change the prefix used for assets to avoid conflicts:
|
57
|
-
|
58
|
-
<ruby>
|
59
|
-
# Defaults to '/assets'
|
60
|
-
config.assets.prefix = '/asset-files'
|
61
|
-
</ruby>
|
62
|
-
|
63
|
-
h5. config/environments/development.rb
|
64
|
-
|
65
|
-
* Remove the RJS setting <tt>config.action_view.debug_rjs = true</tt>.
|
66
|
-
|
67
|
-
* Add the following, if you enable the asset pipeline.
|
68
|
-
|
69
|
-
<ruby>
|
70
|
-
# Do not compress assets
|
71
|
-
config.assets.compress = false
|
72
|
-
|
73
|
-
# Expands the lines which load the assets
|
74
|
-
config.assets.debug = true
|
75
|
-
</ruby>
|
76
|
-
|
77
|
-
h5. config/environments/production.rb
|
78
|
-
|
79
|
-
* Again, most of the changes below are for the asset pipeline. You can read more about these in the "Asset Pipeline":asset_pipeline.html guide.
|
80
|
-
|
81
|
-
<ruby>
|
82
|
-
# Compress JavaScripts and CSS
|
83
|
-
config.assets.compress = true
|
84
|
-
|
85
|
-
# Don't fallback to assets pipeline if a precompiled asset is missed
|
86
|
-
config.assets.compile = false
|
87
|
-
|
88
|
-
# Generate digests for assets URLs
|
89
|
-
config.assets.digest = true
|
90
|
-
|
91
|
-
# Defaults to Rails.root.join("public/assets")
|
92
|
-
# config.assets.manifest = YOUR_PATH
|
93
|
-
|
94
|
-
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
95
|
-
# config.assets.precompile += %w( search.js )
|
96
|
-
|
97
|
-
|
98
|
-
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
99
|
-
# config.force_ssl = true
|
100
|
-
|
101
|
-
</ruby>
|
102
|
-
|
103
|
-
h5. config/environments/test.rb
|
104
|
-
|
105
|
-
<ruby>
|
106
|
-
# Configure static asset server for tests with Cache-Control for performance
|
107
|
-
config.serve_static_assets = true
|
108
|
-
config.static_cache_control = "public, max-age=3600"
|
109
|
-
</ruby>
|
110
|
-
|
111
|
-
h5. config/initializers/wrap_parameters.rb
|
112
|
-
|
113
|
-
* Add this file with the following contents, if you wish to wrap parameters into a nested hash. This is on by default in new applications.
|
114
|
-
|
115
|
-
<ruby>
|
116
|
-
# Be sure to restart your server when you modify this file.
|
117
|
-
# This file contains settings for ActionController::ParamsWrapper which
|
118
|
-
# is enabled by default.
|
119
|
-
|
120
|
-
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
121
|
-
ActiveSupport.on_load(:action_controller) do
|
122
|
-
wrap_parameters :format => [:json]
|
123
|
-
end
|
124
|
-
|
125
|
-
# Disable root element in JSON by default.
|
126
|
-
ActiveSupport.on_load(:active_record) do
|
127
|
-
self.include_root_in_json = false
|
128
|
-
end
|
129
|
-
</ruby>
|
130
|
-
|
131
24
|
h3. Creating a Rails 3.1 application
|
132
25
|
|
133
26
|
<shell>
|
@@ -352,7 +245,7 @@ class User < ActiveRecord::Base
|
|
352
245
|
has_one :account
|
353
246
|
end
|
354
247
|
|
355
|
-
user.build_account{ |a| a.credit_limit
|
248
|
+
user.build_account{ |a| a.credit_limit = 100.0 }
|
356
249
|
</ruby>
|
357
250
|
|
358
251
|
* Added <tt>ActiveRecord::Base.attribute_names</tt> to return a list of attribute names. This will return an empty array if the model is abstract or the table does not exist.
|
@@ -378,7 +271,7 @@ Post.new(params[:post], :as => :admin)
|
|
378
271
|
|
379
272
|
* +ConnectionManagement+ middleware is changed to clean up the connection pool after the rack body has been flushed.
|
380
273
|
|
381
|
-
* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
|
274
|
+
* Added an +update_column+ method on Active Record. This new method updates a given attribute on an object, skipping validations and callbacks. It is recommended to use +update_attributes+ or +update_attribute+ unless you are sure you do not want to execute any callback, including the modification of the +updated_at+ column. It should not be called on new records.
|
382
275
|
|
383
276
|
* Associations with a +:through+ option can now use any association as the through or source association, including other associations which have a +:through+ option and +has_and_belongs_to_many+ associations.
|
384
277
|
|
@@ -422,7 +315,7 @@ end
|
|
422
315
|
<ruby>
|
423
316
|
class MyMigration < ActiveRecord::Migration
|
424
317
|
def change
|
425
|
-
create_table(:horses) do
|
318
|
+
create_table(:horses) do |t|
|
426
319
|
t.column :content, :text
|
427
320
|
t.column :remind_at, :datetime
|
428
321
|
end
|
@@ -16,7 +16,7 @@ h3. What Does a Controller Do?
|
|
16
16
|
|
17
17
|
Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straightforward as possible.
|
18
18
|
|
19
|
-
For most conventional RESTful applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
|
19
|
+
For most conventional "RESTful":http://en.wikipedia.org/wiki/Representational_state_transfer applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
|
20
20
|
|
21
21
|
A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model.
|
22
22
|
|
@@ -166,10 +166,10 @@ h3. Session
|
|
166
166
|
|
167
167
|
Your application has a session for each user in which you can store small amounts of data that will be persisted between requests. The session is only available in the controller and the view and can use one of a number of different storage mechanisms:
|
168
168
|
|
169
|
-
* CookieStore - Stores everything on the client.
|
170
|
-
*
|
171
|
-
*
|
172
|
-
*
|
169
|
+
* ActionDispatch::Session::CookieStore - Stores everything on the client.
|
170
|
+
* ActiveRecord::SessionStore - Stores the data in a database using Active Record.
|
171
|
+
* ActionDispatch::Session::CacheStore - Stores the data in the Rails cache.
|
172
|
+
* ActionDispatch::Session::MemCacheStore - Stores the data in a memcached cluster (this is a legacy implementation; consider using CacheStore instead).
|
173
173
|
|
174
174
|
All session stores use a cookie to store a unique ID for each session (you must use a cookie, Rails will not allow you to pass the session ID in the URL as this is less secure).
|
175
175
|
|
@@ -177,6 +177,8 @@ For most stores this ID is used to look up the session data on the server, e.g.
|
|
177
177
|
|
178
178
|
The CookieStore can store around 4kB of data -- much less than the others -- but this is usually enough. Storing large amounts of data in the session is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error.
|
179
179
|
|
180
|
+
If your user sessions don't store critical data or don't need to be around for long periods (for instance if you just use the flash for messaging), you can consider using ActionDispatch::Session::CacheStore. This will store sessions using the cache implementation you have configured for your application. The advantage of this is that you can use your existing cache infrastructure for storing sessions without requiring any additional setup or administration. The downside, of course, is that the sessions will be ephemeral and could disappear at any time.
|
181
|
+
|
180
182
|
Read more about session storage in the "Security Guide":security.html.
|
181
183
|
|
182
184
|
If you need a different session storage mechanism, you can change it in the +config/initializers/session_store.rb+ file:
|
@@ -684,9 +686,11 @@ end
|
|
684
686
|
|
685
687
|
This will read and stream the file 4kB at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the +:stream+ option or adjust the block size with the +:buffer_size+ option.
|
686
688
|
|
689
|
+
If +:type+ is not specified, it will be guessed from the file extension specified in +:filename+. If the content type is not registered for the extension, <tt>application/octet-stream</tt> will be used.
|
690
|
+
|
687
691
|
WARNING: Be careful when using data coming from the client (params, cookies, etc.) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.
|
688
692
|
|
689
|
-
TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
|
693
|
+
TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
|
690
694
|
|
691
695
|
h4. RESTful Downloads
|
692
696
|
|
@@ -794,7 +798,7 @@ NOTE: Certain exceptions are only rescuable from the +ApplicationController+ cla
|
|
794
798
|
|
795
799
|
h3. Force HTTPS protocol
|
796
800
|
|
797
|
-
Sometime you might want to force a particular controller to only be accessible via an HTTPS protocol for security
|
801
|
+
Sometime you might want to force a particular controller to only be accessible via an HTTPS protocol for security reasons. Since Rails 3.1 you can now use +force_ssl+ method in your controller to enforce that:
|
798
802
|
|
799
803
|
<ruby>
|
800
804
|
class DinnerController
|
@@ -813,9 +817,3 @@ end
|
|
813
817
|
</ruby>
|
814
818
|
|
815
819
|
Please note that if you found yourself adding +force_ssl+ to many controllers, you may found yourself wanting to force the whole application to use HTTPS instead. In that case, you can set the +config.force_ssl+ in your environment file.
|
816
|
-
|
817
|
-
h3. Changelog
|
818
|
-
|
819
|
-
* February 17, 2009: Yet another proofread by Xavier Noria.
|
820
|
-
|
821
|
-
* November 4, 2008: First release version by Tore Darell
|
@@ -362,21 +362,14 @@ When using named routes you only need to supply the +:host+:
|
|
362
362
|
|
363
363
|
Email clients have no web context and so paths have no base URL to form complete web addresses. Thus, when using named routes only the "_url" variant makes sense.
|
364
364
|
|
365
|
-
It is also possible to set a default host that will be used in all mailers by setting the
|
365
|
+
It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option as a configuration option in <tt>config/application.rb</tt>:
|
366
366
|
|
367
367
|
<ruby>
|
368
|
-
|
369
|
-
default_url_options[:host] = "example.com"
|
370
|
-
|
371
|
-
def welcome_email(user)
|
372
|
-
@user = user
|
373
|
-
@url = user_url(@user)
|
374
|
-
mail(:to => user.email,
|
375
|
-
:subject => "Welcome to My Awesome Site")
|
376
|
-
end
|
377
|
-
end
|
368
|
+
config.action_mailer.default_url_options = { :host => "example.com" }
|
378
369
|
</ruby>
|
379
370
|
|
371
|
+
If you use this setting, you should pass the <tt>:only_path => false</tt> option when using +url_for+. This will ensure that absolute URLs are generated because the +url_for+ view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't explicitly provided.
|
372
|
+
|
380
373
|
h4. Sending Multipart Emails
|
381
374
|
|
382
375
|
Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.
|
@@ -401,7 +394,7 @@ Will put the HTML part first, and the plain text part second.
|
|
401
394
|
|
402
395
|
h4. Sending Emails with Attachments
|
403
396
|
|
404
|
-
Attachments can be added by using the +
|
397
|
+
Attachments can be added by using the +attachments+ method:
|
405
398
|
|
406
399
|
<ruby>
|
407
400
|
class UserMailer < ActionMailer::Base
|
@@ -467,7 +460,7 @@ The following configuration options are best made in one of the environment file
|
|
467
460
|
|
468
461
|
h4. Example Action Mailer Configuration
|
469
462
|
|
470
|
-
An example would be adding the following to your appropriate <tt>config/environments
|
463
|
+
An example would be adding the following to your appropriate <tt>config/environments/$RAILS_ENV.rb</tt> file:
|
471
464
|
|
472
465
|
<ruby>
|
473
466
|
config.action_mailer.delivery_method = :sendmail
|
@@ -482,7 +475,7 @@ config.action_mailer.raise_delivery_errors = true
|
|
482
475
|
|
483
476
|
h4. Action Mailer Configuration for GMail
|
484
477
|
|
485
|
-
As Action Mailer now uses the Mail gem, this becomes as simple as adding to your <tt>config/environments
|
478
|
+
As Action Mailer now uses the Mail gem, this becomes as simple as adding to your <tt>config/environments/$RAILS_ENV.rb</tt> file:
|
486
479
|
|
487
480
|
<ruby>
|
488
481
|
config.action_mailer.delivery_method = :smtp
|
@@ -521,7 +514,3 @@ end
|
|
521
514
|
</ruby>
|
522
515
|
|
523
516
|
In the test we send the email and store the returned object in the +email+ variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect.
|
524
|
-
|
525
|
-
h3. Changelog
|
526
|
-
|
527
|
-
* September 30, 2010: Fixed typos and reformatted Action Mailer configuration table for better understanding. "Jaime Iniesta":http://jaimeiniesta.com
|