railties 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
- data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
- data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
- data/guides/assets/stylesheets/main.css +6 -13
- data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
- data/guides/rails_guides/generator.rb +21 -3
- data/guides/source/3_0_release_notes.textile +3 -7
- data/guides/source/action_controller_overview.textile +8 -1
- data/guides/source/action_mailer_basics.textile +1 -1
- data/guides/source/action_view_overview.textile +1 -1
- data/guides/source/active_record_querying.textile +44 -50
- data/guides/source/active_record_validations_callbacks.textile +3 -3
- data/guides/source/caching_with_rails.textile +1 -1
- data/guides/source/configuring.textile +3 -3
- data/guides/source/debugging_rails_applications.textile +6 -4
- data/guides/source/form_helpers.textile +21 -15
- data/guides/source/getting_started.textile +2 -12
- data/guides/source/i18n.textile +6 -0
- data/guides/source/index.html.erb +10 -2
- data/guides/source/layout.html.erb +13 -5
- data/guides/source/layouts_and_rendering.textile +2 -2
- data/guides/source/migrations.textile +1 -1
- data/guides/source/performance_testing.textile +6 -6
- data/guides/source/plugins.textile +9 -9
- data/guides/source/routing.textile +45 -25
- data/guides/source/ruby_on_rails_guides_guidelines.textile +77 -0
- data/lib/rails/application/configuration.rb +2 -0
- data/lib/rails/application/finisher.rb +7 -0
- data/lib/rails/code_statistics.rb +1 -1
- data/lib/rails/commands/console.rb +1 -1
- data/lib/rails/commands/runner.rb +2 -2
- data/lib/rails/engine/configuration.rb +6 -0
- data/lib/rails/generators/generated_attribute.rb +1 -0
- data/lib/rails/generators/rails/app/app_generator.rb +7 -4
- data/lib/rails/generators/rails/app/templates/Gemfile +2 -3
- data/lib/rails/generators/rails/app/templates/README +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/resource_helpers.rb +1 -1
- data/lib/rails/plugin.rb +1 -1
- data/lib/rails/railtie.rb +1 -1
- data/lib/rails/railtie/configuration.rb +4 -3
- data/lib/rails/ruby_version_check.rb +1 -2
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/version.rb +2 -2
- metadata +70 -15
- data/guides/assets/javascripts/code_highlighter.js +0 -188
- data/guides/assets/javascripts/highlighters.js +0 -90
- data/guides/assets/stylesheets/syntax.css +0 -31
@@ -1128,14 +1128,14 @@ As with callback classes, the observer's methods receive the observed model as a
|
|
1128
1128
|
|
1129
1129
|
h4. Registering Observers
|
1130
1130
|
|
1131
|
-
Observers are conventionally placed inside of your +app/models+ directory and registered in your application's +config/
|
1131
|
+
Observers are conventionally placed inside of your +app/models+ directory and registered in your application's +config/application.rb+ file. For example, the +UserObserver+ above would be saved as +app/models/user_observer.rb+ and registered in +config/application.rb+ this way:
|
1132
1132
|
|
1133
1133
|
<ruby>
|
1134
1134
|
# Activate observers that should always be running
|
1135
1135
|
config.active_record.observers = :user_observer
|
1136
1136
|
</ruby>
|
1137
1137
|
|
1138
|
-
As usual, settings in +config/environments+ take precedence over those in +config/
|
1138
|
+
As usual, settings in +config/environments+ take precedence over those in +config/application.rb+. So, if you prefer that an observer doesn't run in all environments, you can simply register it in a specific environment instead.
|
1139
1139
|
|
1140
1140
|
h4. Sharing Observers
|
1141
1141
|
|
@@ -1151,7 +1151,7 @@ class MailerObserver < ActiveRecord::Observer
|
|
1151
1151
|
end
|
1152
1152
|
</ruby>
|
1153
1153
|
|
1154
|
-
In this example, the +after_create+ method would be called whenever a +Registration+ or +User+ was created. Note that this new +MailerObserver+ would also need to be registered in +config/
|
1154
|
+
In this example, the +after_create+ method would be called whenever a +Registration+ or +User+ was created. Note that this new +MailerObserver+ would also need to be registered in +config/application.rb+ in order to take effect.
|
1155
1155
|
|
1156
1156
|
<ruby>
|
1157
1157
|
# Activate observers that should always be running
|
@@ -364,7 +364,7 @@ end
|
|
364
364
|
|
365
365
|
h3. Advanced Caching
|
366
366
|
|
367
|
-
Along with the built-in mechanisms outlined above, a number of excellent plugins exist to help with finer grained control over caching. These include Chris Wanstrath's excellent cache_fu plugin (more info "here":
|
367
|
+
Along with the built-in mechanisms outlined above, a number of excellent plugins exist to help with finer grained control over caching. These include Chris Wanstrath's excellent cache_fu plugin (more info "here":http://errtheblog.com/posts/57-kickin-ass-w-cachefu ) and Evan Weaver's interlock plugin (more info "here":http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/ ). Both of these plugins play nice with memcached and are a must-see for anyone
|
368
368
|
seriously considering optimizing their caching needs.
|
369
369
|
|
370
370
|
Also the new "Cache money":http://github.com/nkallen/cache-money/tree/master plugin is supposed to be mad cool.
|
@@ -32,7 +32,7 @@ config.filter_parameters << :password
|
|
32
32
|
This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object:
|
33
33
|
|
34
34
|
<ruby>
|
35
|
-
config.active_record.
|
35
|
+
config.active_record.timestamped_migrations = false
|
36
36
|
</ruby>
|
37
37
|
|
38
38
|
Rails will use that particular setting to configure Active Record.
|
@@ -45,6 +45,8 @@ h4. Rails General Configuration
|
|
45
45
|
|
46
46
|
* +config.cache_store+ configures which cache store to use for Rails caching. Options include +:memory_store+, +:file_store+, +:mem_cache_store+ or the name of your own custom class.
|
47
47
|
|
48
|
+
* +config.colorize_logging+ (true by default) specifies whether or not to use ANSI color codes when logging information.
|
49
|
+
|
48
50
|
* +config.controller_paths+ accepts an array of paths that will be searched for controllers. Defaults to +app/controllers+.
|
49
51
|
|
50
52
|
* +config.database_configuration_file+ overrides the default path for the database configuration file. Default to +config/database.yml+.
|
@@ -105,8 +107,6 @@ h4. Configuring Active Record
|
|
105
107
|
|
106
108
|
* +config.active_record.pluralize_table_names+ specifies whether Rails will look for singular or plural table names in the database. If set to +true+ (the default), then the Customer class will use the +customers+ table. If set to +false+, then the Customers class will use the +customer+ table.
|
107
109
|
|
108
|
-
* +config.active_record.colorize_logging+ (true by default) specifies whether or not to use ANSI color codes when logging information from ActiveRecord.
|
109
|
-
|
110
110
|
* +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:local+.
|
111
111
|
|
112
112
|
* +config.active_record.schema_format+ controls the format for dumping the database schema to a file. The options are +:ruby+ (the default) for a database-independent version that depends on migrations, or +:sql+ for a set of (potentially database-dependent) SQL statements.
|
@@ -127,8 +127,8 @@ Rails makes use of Ruby's standard +logger+ to write log information. You can al
|
|
127
127
|
You can specify an alternative logger in your +environment.rb+ or any environment file:
|
128
128
|
|
129
129
|
<ruby>
|
130
|
-
|
131
|
-
|
130
|
+
Rails.logger = Logger.new(STDOUT)
|
131
|
+
Rails.logger = Log4r::Logger.new("Application Log")
|
132
132
|
</ruby>
|
133
133
|
|
134
134
|
Or in the +Initializer+ section, add _any_ of the following
|
@@ -142,13 +142,13 @@ TIP: By default, each log is created under +Rails.root/log/+ and the log file na
|
|
142
142
|
|
143
143
|
h4. Log Levels
|
144
144
|
|
145
|
-
When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the +
|
145
|
+
When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the +Rails.logger.level+ method.
|
146
146
|
|
147
147
|
The available log levels are: +:debug+, +:info+, +:warn+, +:error+, and +:fatal+, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use
|
148
148
|
|
149
149
|
<ruby>
|
150
150
|
config.log_level = Logger::WARN # In any environment initializer, or
|
151
|
-
|
151
|
+
Rails.logger.level = 0 # at any time
|
152
152
|
</ruby>
|
153
153
|
|
154
154
|
This is useful when you want to log under development or staging, but you don't want to flood your production log with unnecessary information.
|
@@ -225,6 +225,8 @@ The debugger used by Rails, +ruby-debug+, comes as a gem. To install it, just ru
|
|
225
225
|
$ sudo gem install ruby-debug
|
226
226
|
</shell>
|
227
227
|
|
228
|
+
TIP: If you are using Ruby 1.9, you can install a compatible version of +ruby-debug+ by running +sudo gem install ruby-debug19+
|
229
|
+
|
228
230
|
In case you want to download a particular version or get the source code, refer to the "project's page on rubyforge":http://rubyforge.org/projects/ruby-debug/.
|
229
231
|
|
230
232
|
Rails has had built-in support for ruby-debug since Rails 2.0. Inside any Rails application you can invoke the debugger by calling the +debugger+ method.
|
@@ -58,13 +58,13 @@ To create this form you will use +form_tag+, +label_tag+, +text_field_tag+, and
|
|
58
58
|
|
59
59
|
A basic search form
|
60
60
|
|
61
|
-
<
|
61
|
+
<erb>
|
62
62
|
<%= form_tag(search_path, :method => "get") do %>
|
63
63
|
<%= label_tag(:q, "Search for:") %>
|
64
64
|
<%= text_field_tag(:q) %>
|
65
65
|
<%= submit_tag("Search") %>
|
66
66
|
<% end %>
|
67
|
-
</
|
67
|
+
</erb>
|
68
68
|
|
69
69
|
TIP: +search_path+ can be a named route specified in "routes.rb": <br /><tt>map.search "search", :controller => "search"</tt>
|
70
70
|
|
@@ -106,7 +106,7 @@ WARNING: Do not delimit the second hash without doing so with the first hash, ot
|
|
106
106
|
|
107
107
|
h4. Helpers for Generating Form Elements
|
108
108
|
|
109
|
-
Rails provides a series of helpers for generating form elements such as checkboxes, text fields, radio buttons, and so on. These basic helpers, with names ending in <notextile>_tag</notextile> such as +text_field_tag+, +check_box_tag+,
|
109
|
+
Rails provides a series of helpers for generating form elements such as checkboxes, text fields, radio buttons, and so on. These basic helpers, with names ending in <notextile>_tag</notextile> such as +text_field_tag+, +check_box_tag+, generate just a single +<input>+ element. The first parameter to these is always the name of the input. In the controller this name will be the key in the +params+ hash used to get the value entered by the user. For example, if the form contains
|
110
110
|
|
111
111
|
<erb>
|
112
112
|
<%= text_field_tag(:query) %>
|
@@ -126,17 +126,19 @@ Checkboxes are form controls that give the user a set of options they can enable
|
|
126
126
|
|
127
127
|
<erb>
|
128
128
|
<%= check_box_tag(:pet_dog) %>
|
129
|
-
|
129
|
+
<%= label_tag(:pet_dog, "I own a dog") %>
|
130
130
|
<%= check_box_tag(:pet_cat) %>
|
131
|
-
|
131
|
+
<%= label_tag(:pet_cat, "I own a cat") %>
|
132
|
+
</erb>
|
132
133
|
|
133
134
|
output:
|
134
135
|
|
136
|
+
<html>
|
135
137
|
<input id="pet_dog" name="pet_dog" type="checkbox" value="1" />
|
136
|
-
|
138
|
+
<label for="pet_dog">I own a dog</label>
|
137
139
|
<input id="pet_cat" name="pet_cat" type="checkbox" value="1" />
|
138
|
-
|
139
|
-
</
|
140
|
+
<label for="pet_cat">I own a cat</label>
|
141
|
+
</html>
|
140
142
|
|
141
143
|
The second parameter to +check_box_tag+ is the value of the input. This is the value that will be submitted by the browser if the checkbox is ticked (i.e. the value that will be present in the +params+ hash). With the above form you would check the value of +params[:pet_dog]+ and +params[:pet_cat]+ to see which pets the user owns.
|
142
144
|
|
@@ -146,17 +148,19 @@ Radio buttons, while similar to checkboxes, are controls that specify a set of o
|
|
146
148
|
|
147
149
|
<erb>
|
148
150
|
<%= radio_button_tag(:age, "child") %>
|
149
|
-
|
151
|
+
<%= label_tag(:age_child, "I am younger than 21") %>
|
150
152
|
<%= radio_button_tag(:age, "adult") %>
|
151
|
-
|
153
|
+
<%= label_tag(:age_adult, "I'm over 21") %>
|
154
|
+
</erb>
|
152
155
|
|
153
156
|
output:
|
154
157
|
|
158
|
+
<html>
|
155
159
|
<input id="age_child" name="age" type="radio" value="child" />
|
156
|
-
|
160
|
+
<label for="age_child">I am younger than 21</label>
|
157
161
|
<input id="age_adult" name="age" type="radio" value="adult" />
|
158
|
-
|
159
|
-
</
|
162
|
+
<label for="age_adult">I'm over 21</label>
|
163
|
+
</html>
|
160
164
|
|
161
165
|
As with +check_box_tag+ the second parameter to +radio_button_tag+ is the value of the input. Because these two radio buttons share the same name (age) the user will only be able to select one and +params[:age]+ will contain either "child" or "adult".
|
162
166
|
|
@@ -170,13 +174,15 @@ Other form controls worth mentioning are the text area, password input and hidde
|
|
170
174
|
<%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %>
|
171
175
|
<%= password_field_tag(:password) %>
|
172
176
|
<%= hidden_field_tag(:parent_id, "5") %>
|
177
|
+
</erb>
|
173
178
|
|
174
179
|
output:
|
175
180
|
|
181
|
+
<html>
|
176
182
|
<textarea id="message" name="message" cols="24" rows="6">Hi, nice site</textarea>
|
177
183
|
<input id="password" name="password" type="password" />
|
178
184
|
<input id="parent_id" name="parent_id" type="hidden" value="5" />
|
179
|
-
</
|
185
|
+
</html>
|
180
186
|
|
181
187
|
Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript.
|
182
188
|
|
@@ -277,7 +283,7 @@ h4. Relying on Record Identification
|
|
277
283
|
The Article model is directly available to users of the application, so -- following the best practices for developing with Rails -- you should declare it *a resource*:
|
278
284
|
|
279
285
|
<ruby>
|
280
|
-
|
286
|
+
resources :articles
|
281
287
|
</ruby>
|
282
288
|
|
283
289
|
TIP: Declaring a resource has a number of side-affects. See "Rails Routing From the Outside In":routing.html#resource-routing-the-rails-default for more information on setting up and using resources.
|
@@ -149,9 +149,7 @@ Usually run this as the root user:
|
|
149
149
|
# gem install rails
|
150
150
|
</shell>
|
151
151
|
|
152
|
-
|
153
|
-
|
154
|
-
TIP. If you're working on Windows, you may find it easier to install "Instant Rails":http://instantrails.rubyforge.org/wiki/wiki.pl. Be aware, though, that Instant Rails releases tend to lag seriously behind the actual Rails version. Also, you will find that Rails development on Windows is overall less pleasant than on other operating systems. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows.
|
152
|
+
TIP. If you're working on Windows, you should be aware that the vast majority of Rails development is done in Unix environments. While Ruby and Rails themselves install easily using for example "Ruby Installer":http://rubyinstaller.org/, the supporting ecosystem often assumes you are able to build C-based rubygems and work in a command window. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows.
|
155
153
|
|
156
154
|
h4. Creating the Blog Application
|
157
155
|
|
@@ -729,7 +727,6 @@ After finding the requested post, Rails uses the +edit.html.erb+ view to display
|
|
729
727
|
|
730
728
|
<%= link_to 'Show', @post %> |
|
731
729
|
<%= link_to 'Back', posts_path %>
|
732
|
-
<% end %>
|
733
730
|
</erb>
|
734
731
|
|
735
732
|
Again, as with the +new+ action, the +edit+ action is using the +form+ partial, this time however, the form will do a PUT action to the PostsController and the submit button will display "Update Post"
|
@@ -922,8 +919,6 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+
|
|
922
919
|
|
923
920
|
<h2>Add a comment:</h2>
|
924
921
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
925
|
-
<%= f.error_messages %>
|
926
|
-
|
927
922
|
<div class="field">
|
928
923
|
<%= f.label :commenter %><br />
|
929
924
|
<%= f.text_field :commenter %>
|
@@ -992,8 +987,6 @@ Once we have made the new comment, we send the user back to the original post us
|
|
992
987
|
|
993
988
|
<h2>Add a comment:</h2>
|
994
989
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
995
|
-
<%= f.error_messages %>
|
996
|
-
|
997
990
|
<div class="field">
|
998
991
|
<%= f.label :commenter %><br />
|
999
992
|
<%= f.text_field :commenter %>
|
@@ -1061,8 +1054,6 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f
|
|
1061
1054
|
|
1062
1055
|
<h2>Add a comment:</h2>
|
1063
1056
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
1064
|
-
<%= f.error_messages %>
|
1065
|
-
|
1066
1057
|
<div class="field">
|
1067
1058
|
<%= f.label :commenter %><br />
|
1068
1059
|
<%= f.text_field :commenter %>
|
@@ -1090,8 +1081,6 @@ Lets also move that new comment section out to it's own partial, again, you crea
|
|
1090
1081
|
|
1091
1082
|
<erb>
|
1092
1083
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
1093
|
-
<%= f.error_messages %>
|
1094
|
-
|
1095
1084
|
<div class="field">
|
1096
1085
|
<%= f.label :commenter %><br />
|
1097
1086
|
<%= f.text_field :commenter %>
|
@@ -1486,6 +1475,7 @@ h3. Changelog
|
|
1486
1475
|
|
1487
1476
|
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
|
1488
1477
|
|
1478
|
+
* August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl
|
1489
1479
|
* July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com
|
1490
1480
|
* May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com
|
1491
1481
|
* April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com
|
data/guides/source/i18n.textile
CHANGED
@@ -686,6 +686,8 @@ The key for the error message in this case is +:blank+. Active Record will look
|
|
686
686
|
activerecord.errors.models.[model_name].attributes.[attribute_name]
|
687
687
|
activerecord.errors.models.[model_name]
|
688
688
|
activerecord.errors.messages
|
689
|
+
errors.attributes.[attribute_name]
|
690
|
+
errors.messages
|
689
691
|
</ruby>
|
690
692
|
|
691
693
|
Thus, in our example it will try the following keys in this order and return the first result:
|
@@ -694,6 +696,8 @@ Thus, in our example it will try the following keys in this order and return the
|
|
694
696
|
activerecord.errors.models.user.attributes.name.blank
|
695
697
|
activerecord.errors.models.user.blank
|
696
698
|
activerecord.errors.messages.blank
|
699
|
+
errors.attributes.name.blank
|
700
|
+
errors.messagges.blank
|
697
701
|
</ruby>
|
698
702
|
|
699
703
|
When your models are additionally using inheritance then the messages are looked up in the inheritance chain.
|
@@ -714,6 +718,8 @@ activerecord.errors.models.admin.blank
|
|
714
718
|
activerecord.errors.models.user.attributes.title.blank
|
715
719
|
activerecord.errors.models.user.blank
|
716
720
|
activerecord.errors.messages.blank
|
721
|
+
errors.attributes.title.blank
|
722
|
+
errors.messagges.blank
|
717
723
|
</ruby>
|
718
724
|
|
719
725
|
This way you can provide special translations for various error messages at different points in your models inheritance chain and in the attributes, models, or default scopes.
|
@@ -3,7 +3,7 @@ Ruby on Rails Guides
|
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
<% content_for :header_section do %>
|
6
|
-
<h2>Ruby on Rails Guides</h2>
|
6
|
+
<h2>Ruby on Rails Guides (<%= ENV['RAILS_VERSION'] || 'edge' %>)</h2>
|
7
7
|
|
8
8
|
<% if @edge %>
|
9
9
|
<p>
|
@@ -14,8 +14,12 @@ Ruby on Rails Guides
|
|
14
14
|
If you are looking for the ones for the stable version please check
|
15
15
|
<a href="http://guides.rubyonrails.org">http://guides.rubyonrails.org</a> instead.
|
16
16
|
</p>
|
17
|
+
<% else %>
|
18
|
+
<p>
|
19
|
+
These are the new guides for Rails 3. The guides for Rails 2.3 are still available
|
20
|
+
at <a href="http://guides.rubyonrails.org/v2.3.8/">http://guides.rubyonrails.org/v2.3.8/</a>.
|
21
|
+
</p>
|
17
22
|
<% end %>
|
18
|
-
|
19
23
|
<p>
|
20
24
|
These guides are designed to make you immediately productive with Rails,
|
21
25
|
and to help you understand how all of the pieces fit together.
|
@@ -157,6 +161,10 @@ Ruby on Rails Guides
|
|
157
161
|
<%= guide('API Documentation Guidelines', 'api_documentation_guidelines.html') do %>
|
158
162
|
<p>This guide documents the Ruby on Rails API documentation guidelines.</p>
|
159
163
|
<% end %>
|
164
|
+
|
165
|
+
<%= guide('Ruby on Rails Guides Guidelines', 'ruby_on_rails_guides_guidelines.html') do %>
|
166
|
+
<p>This guide documents the Ruby on Rails guides guidelines.</p>
|
167
|
+
<% end %>
|
160
168
|
</dl>
|
161
169
|
|
162
170
|
<h3>Release Notes</h3>
|
@@ -8,13 +8,10 @@
|
|
8
8
|
<title><%= yield(:page_title) || 'Ruby on Rails guides' %></title>
|
9
9
|
|
10
10
|
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
11
|
-
<link rel="stylesheet" type="text/css" href="stylesheets/syntax.css" />
|
12
11
|
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
13
12
|
|
14
|
-
<
|
15
|
-
<
|
16
|
-
<script type="text/javascript" src="javascripts/highlighters.js"></script>
|
17
|
-
|
13
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
14
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
18
15
|
</head>
|
19
16
|
<body class="guide">
|
20
17
|
<% if @edge %>
|
@@ -81,6 +78,7 @@
|
|
81
78
|
<dt>Contributing to Rails</dt>
|
82
79
|
<dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
|
83
80
|
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
81
|
+
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
84
82
|
|
85
83
|
<dt>Release Notes</dt>
|
86
84
|
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
@@ -119,5 +117,15 @@
|
|
119
117
|
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
120
118
|
</div>
|
121
119
|
</div>
|
120
|
+
|
121
|
+
<script type="text/javascript" src="javascripts/guides.js"></script>
|
122
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
123
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
124
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
125
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
126
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
127
|
+
<script type="text/javascript">
|
128
|
+
SyntaxHighlighter.all()
|
129
|
+
</script>
|
122
130
|
</body>
|
123
131
|
</html>
|
@@ -971,7 +971,7 @@ Partial templates - usually just called "partials" - are another device for brea
|
|
971
971
|
|
972
972
|
h5. Naming Partials
|
973
973
|
|
974
|
-
To render a partial as part of a view, you use the +render+ method within the view
|
974
|
+
To render a partial as part of a view, you use the +render+ method within the view:
|
975
975
|
|
976
976
|
<ruby>
|
977
977
|
<%= render "menu" %>
|
@@ -1087,7 +1087,7 @@ Partials are very useful in rendering collections. When you pass a collection to
|
|
1087
1087
|
|
1088
1088
|
When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is +_product+, and within the +_product+ partial, you can refer to +product+ to get the instance that is being rendered.
|
1089
1089
|
|
1090
|
-
In Rails 3.0 there is also a shorthand for this, assuming +@
|
1090
|
+
In Rails 3.0 there is also a shorthand for this, assuming +@products+ is a collection of +product+ instances, you can simply do in the +index.html.erb+:
|
1091
1091
|
|
1092
1092
|
<erb>
|
1093
1093
|
<h1>Products</h1>
|
@@ -546,7 +546,7 @@ Schema files are also useful if you want a quick look at what attributes an Acti
|
|
546
546
|
|
547
547
|
h4. Types of Schema Dumps
|
548
548
|
|
549
|
-
There are two ways to dump the schema. This is set in +config/
|
549
|
+
There are two ways to dump the schema. This is set in +config/application.rb+ by the +config.active_record.schema_format+ setting, which may be either +:sql+ or +:ruby+.
|
550
550
|
|
551
551
|
If +:ruby+ is selected then the schema is stored in +db/schema.rb+. If you look at this file you'll find that it looks an awful lot like one very big migration:
|
552
552
|
|
@@ -20,7 +20,7 @@ In a freshly generated Rails application, +test/performance/browsing_test.rb+ co
|
|
20
20
|
|
21
21
|
<ruby>
|
22
22
|
require 'test_helper'
|
23
|
-
require 'performance_test_help'
|
23
|
+
require 'rails/performance_test_help'
|
24
24
|
|
25
25
|
# Profiling results for each test method are written to tmp/performance.
|
26
26
|
class BrowsingTest < ActionController::PerformanceTest
|
@@ -34,17 +34,17 @@ This example is a simple performance test case for profiling a GET request to th
|
|
34
34
|
|
35
35
|
h4. Generating Performance Tests
|
36
36
|
|
37
|
-
Rails provides a generator called +
|
37
|
+
Rails provides a generator called +test_unit:performance+ for creating new performance tests:
|
38
38
|
|
39
39
|
<shell>
|
40
|
-
rails generate
|
40
|
+
rails generate test_unit:performance homepage
|
41
41
|
</shell>
|
42
42
|
|
43
43
|
This generates +homepage_test.rb+ in the +test/performance+ directory:
|
44
44
|
|
45
45
|
<ruby>
|
46
46
|
require 'test_helper'
|
47
|
-
require 'performance_test_help'
|
47
|
+
require 'rails/performance_test_help'
|
48
48
|
|
49
49
|
class HomepageTest < ActionController::PerformanceTest
|
50
50
|
# Replace this with your real tests.
|
@@ -103,7 +103,7 @@ Here's the performance test for +HomeController#dashboard+ and +PostsController#
|
|
103
103
|
|
104
104
|
<ruby>
|
105
105
|
require 'test_helper'
|
106
|
-
require 'performance_test_help'
|
106
|
+
require 'rails/performance_test_help'
|
107
107
|
|
108
108
|
class PostPerformanceTest < ActionController::PerformanceTest
|
109
109
|
def setup
|
@@ -131,7 +131,7 @@ Performance test for +Post+ model:
|
|
131
131
|
|
132
132
|
<ruby>
|
133
133
|
require 'test_helper'
|
134
|
-
require 'performance_test_help'
|
134
|
+
require 'rails/performance_test_help'
|
135
135
|
|
136
136
|
class PostModelTest < ActionController::PerformanceTest
|
137
137
|
def test_creation
|
@@ -33,20 +33,20 @@ h3. Setup
|
|
33
33
|
|
34
34
|
h4. Create the Basic Application
|
35
35
|
|
36
|
-
The examples in this guide require that you have a working rails application. To create a simple
|
36
|
+
The examples in this guide require that you have a working rails application. To create a simple one execute:
|
37
37
|
|
38
38
|
<shell>
|
39
39
|
gem install rails
|
40
|
-
rails yaffle_guide
|
40
|
+
rails new yaffle_guide
|
41
41
|
cd yaffle_guide
|
42
42
|
rails generate scaffold bird name:string
|
43
43
|
rake db:migrate
|
44
44
|
rails server
|
45
45
|
</shell>
|
46
46
|
|
47
|
-
Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails
|
47
|
+
Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails application before continuing.
|
48
48
|
|
49
|
-
NOTE: The aforementioned instructions will work for sqlite3. For more detailed instructions on how to create a rails
|
49
|
+
NOTE: The aforementioned instructions will work for sqlite3. For more detailed instructions on how to create a rails application for other databases see the API docs.
|
50
50
|
|
51
51
|
|
52
52
|
h4. Generate the Plugin Skeleton
|
@@ -277,7 +277,7 @@ Now you are ready to test-drive your plugin!
|
|
277
277
|
|
278
278
|
h3. Extending Core Classes
|
279
279
|
|
280
|
-
This section will explain how to add a method to String that will be available anywhere in your rails
|
280
|
+
This section will explain how to add a method to String that will be available anywhere in your rails application.
|
281
281
|
|
282
282
|
In this example you will add a method to String named +to_squawk+. To begin, create a new test file with a few assertions:
|
283
283
|
|
@@ -622,7 +622,7 @@ create_table :woodpeckers, :force => true do |t|
|
|
622
622
|
end
|
623
623
|
</ruby>
|
624
624
|
|
625
|
-
Now your test should be passing, and you should be able to use the Woodpecker model from within your rails
|
625
|
+
Now your test should be passing, and you should be able to use the Woodpecker model from within your rails application, and any changes made to it are reflected immediately when running in development mode.
|
626
626
|
|
627
627
|
h3. Controllers
|
628
628
|
|
@@ -734,7 +734,7 @@ h3. Routes
|
|
734
734
|
|
735
735
|
In a standard 'routes.rb' file you use routes like 'map.connect' or 'map.resources'. You can add your own custom routes from a plugin. This section will describe how to add a custom method called that can be called with 'map.yaffles'.
|
736
736
|
|
737
|
-
Testing routes from plugins is slightly different from testing routes in a standard rails
|
737
|
+
Testing routes from plugins is slightly different from testing routes in a standard rails application. To begin, add a test like this:
|
738
738
|
|
739
739
|
* *vendor/plugins/yaffle/test/routing_test.rb*
|
740
740
|
|
@@ -798,7 +798,7 @@ You can also see if your routes work by running +rake routes+ from your app dire
|
|
798
798
|
|
799
799
|
h3. Generators
|
800
800
|
|
801
|
-
Many plugins ship with generators. When you created the plugin above, you specified the +--
|
801
|
+
Many plugins ship with generators. When you created the plugin above, you specified the +--generator+ option, so you already have the generator stubs in 'vendor/plugins/yaffle/generators/yaffle'.
|
802
802
|
|
803
803
|
Building generators is a complex topic unto itself and this section will cover one small aspect of generators: generating a simple text file.
|
804
804
|
|
@@ -1385,7 +1385,7 @@ rake gem
|
|
1385
1385
|
sudo gem install pkg/yaffle-0.0.1.gem
|
1386
1386
|
</shell>
|
1387
1387
|
|
1388
|
-
To test this, create a new rails
|
1388
|
+
To test this, create a new rails application, add +config.gem "yaffle"+ to +config/environment.rb+ and all of your plugin's functionality will be available to you.
|
1389
1389
|
|
1390
1390
|
h3. RDoc Documentation
|
1391
1391
|
|