aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/action_view_overview.textile4
-rw-r--r--railties/guides/source/active_support_core_extensions.textile6
-rw-r--r--railties/guides/source/association_basics.textile2
-rw-r--r--railties/guides/source/contribute.textile2
-rw-r--r--railties/guides/source/credits.html.erb66
-rw-r--r--railties/guides/source/credits.textile.erb60
-rw-r--r--railties/guides/source/debugging_rails_applications.textile3
-rw-r--r--railties/guides/source/form_helpers.textile2
-rw-r--r--railties/guides/source/getting_started.textile5
-rw-r--r--railties/guides/source/index.html.erb150
-rw-r--r--railties/guides/source/index.textile.erb139
-rw-r--r--railties/guides/source/layout.html.erb22
-rw-r--r--railties/guides/source/layouts_and_rendering.textile5
-rw-r--r--railties/guides/source/performance_testing.textile8
-rw-r--r--railties/guides/source/plugins.textile29
-rw-r--r--railties/guides/source/routing.textile151
-rw-r--r--railties/guides/source/security.textile10
-rw-r--r--railties/guides/source/testing.textile3
18 files changed, 304 insertions, 363 deletions
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index a517193cea..842a8408ad 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -1079,7 +1079,7 @@ h4. JavaScriptHelper
Provides functionality for working with JavaScript in your views.
-Rails includes the Prototype JavaScript framework and the Scriptaculous JavaScript controls and visual effects library. If you wish to use these libraries and their helpers, make sure +<%= javascript_include_tag :defaults, :cache => true %>+ is in the HEAD section of your page. This function will include the necessary JavaScript files Rails generated in the public/javascripts directory.
+Rails includes the Prototype JavaScript framework and the Scriptaculous JavaScript controls and visual effects library. If you wish to use these libraries and their helpers, make sure +&lt;%= javascript_include_tag :defaults, :cache => true %&gt;+ is in the HEAD section of your page. This function will include the necessary JavaScript files Rails generated in the public/javascripts directory.
h5. button_to_function
@@ -1414,7 +1414,7 @@ Replaces the inner HTML of the DOM element with the given id.
page.replace_html 'person-45', :partial => 'person', :object => @person
</ruby>
-h5. select
+h5(#prototype-select). select
Returns a collection reference by finding it through a CSS pattern in the DOM.
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index a8410a8dd2..b41b16b728 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -866,7 +866,7 @@ WARNING: Note that in that case +parent+ returns +Object+.
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
-h5. +parents+
+h5(#module-parents). +parents+
The method +parents+ calls +parent+ on the receiver and upwards until +Object+ is reached. The chain is returned in an array, from bottom to top:
@@ -2191,9 +2191,9 @@ NOTE: Defined in +active_support/core_ext/array/grouping.rb+.
h3. Extensions to +Hash+
-h4. Conversions
+h4(#hash-conversions). Conversions
-h5. +to_xml+
+h5(#hash-to-xml). +to_xml+
The method +to_xml+ returns a string containing an XML representation of its receiver:
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 757dce1f4e..4256466bec 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -417,7 +417,7 @@ h5. Creating Join Tables for +has_and_belongs_to_many+ Associations
If you create a +has_and_belongs_to_many+ association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the +:join_table+ option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering.
-WARNING: The precedence between model names is calculated using the +<+ operator for +String+. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers" (because the underscore '_' is lexicographically _less_ than 's' in common encodings).
+WARNING: The precedence between model names is calculated using the +&lt;+ operator for +String+. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers" (because the underscore '_' is lexicographically _less_ than 's' in common encodings).
Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations:
diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile
index 1203e38a4e..8c64df5362 100644
--- a/railties/guides/source/contribute.textile
+++ b/railties/guides/source/contribute.textile
@@ -9,7 +9,7 @@ h3. How to Contribute?
* We have an open commit policy: anyone is welcome to contribute, but you'll need to ask for commit access.
* PM lifo at "GitHub":http://github.com asking for "docrails":http://github.com/lifo/docrails/tree/master commit access.
* Guides are written in Textile, and reside at railties/guides/source in the docrails project.
-* All images are in the railties/guides/images directory.
+* Assets are stored in the +railties/guides/assets+ directory.
* Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile
* Sample output : "Active Record Associations":association_basics.html
* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory.
diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb
new file mode 100644
index 0000000000..9851702df9
--- /dev/null
+++ b/railties/guides/source/credits.html.erb
@@ -0,0 +1,66 @@
+<% content_for :header_section do %>
+<h2>Credits</h2>
+
+<p>We'd like to thank the following people for their tireless contributions to this project.</p>
+
+<% end %>
+
+<h3 class="section">Rails Documentation Team</h3>
+
+<%= author('Mike Gunderloy', 'mgunderloy') do %>
+ Mike Gunderloy is a consultant with <a href="http://www.actionrails.com">ActionRails</a>. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at <a href="http://afreshcup.com">A Fresh Cup</a> and he <a href="http://twitter.com/MikeG1">twitters</a> too much.
+<% end %>
+
+<%= author('Pratik Naik', 'lifo') do %>
+ Pratik Naik is a Ruby on Rails consultant with <a href="http://www.actionrails.com">ActionRails</a> and also a member of the <a href="http://rubyonrails.org/core">Rails core team</a>. He maintains a blog at <a href="http://m.onkey.org">has_many :bugs, :through =&gt; :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a>.
+<% end %>
+
+<%= author('Xavier Noria', 'fxn', 'fxn.png') do %>
+ Xavier has been into Rails since 2005, he is currently a Rails consultant. Xavier is Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as &quot;fxn&quot;.
+<% end %>
+
+<h3 class="section">Rails Guides Designers</h3>
+
+<%= author('Jason Zimdars', 'jz') do %>
+ Jason Zimdars is an experienced creative director and web designer who has lead UI and UX design for numerous websites and web applications. You can see more of his design and writing at <a href="http://www.thinkcage.com/">Thinkcage.com</a> or follow him on <a href="http://twitter.com/JZ">Twitter</a>.
+<% end %>
+
+<h3 class="section">Rails Guides Authors</h3>
+
+<%= author('Frederick Cheung', 'fcheung') do %>
+ Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.
+<% end %>
+
+<%= author('Tore Darell', 'toretore') do %>
+ Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
+<% end %>
+
+<%= author('Jeff Dean', 'zilkey') do %>
+ Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>.
+<% end %>
+
+<%= author('Cássio Marques', 'cmarques') do %>
+ Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at <a href="http://cassiomarques.wordpress.com">/* CODIFICANDO */</a>, which is mainly written in Portuguese, but will soon get a new section for posts with English translation.
+<% end %>
+
+<%= author('James Miller', 'bensie') do %>
+ James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. Find me on GitHub, Gmail, Twitter, and Freenode as &quot;bensie&quot;.
+<% end %>
+
+<%= author('Emilio Tagua', 'miloops') do %>
+ Emilio Tagua &mdash;a.k.a. miloops&mdash; is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of <a href="http://eventioz.com">Eventioz</a>. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as &quot;miloops&quot;.
+<% end %>
+
+<%= author('Heiko Webers', 'hawe') do %>
+ Heiko Webers is the founder of <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the <a href="http://www.rorsecurity.info">Ruby on Rails Security Project</a>. After 10 years of desktop application development, Heiko has rarely looked back.
+<% end %>
+
+<%= author('Mikel Lindsaar', 'raasdnil') do %>
+ Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby Mail gem and core contributor (he helped re-write Action Mailer's API). Mikel has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>.
+<% end %>
+
+<h3 class="section">Rails Guides Reviewers</h3>
+
+<%= author('Jaime Iniesta', 'jaimeiniesta', 'jaimeiniesta.jpg') do %>
+ Jaime Iniesta works as a Ruby on Rails freelance developer since 2005. He's a member of <a href="http://www.prorubyteam.com">ProRuby</a>, co-founder of the <a href="http://srug.org">Spanish Ruby Users Group</a>, member of <a href="http://spainrb.org">Spain.rb</a>, and organizer of <a href="http://conferenciarails.org">Conferencia Rails</a> and <a href="http://euruko2009.org">EuRuKo 2009</a>. Jaime has a <a href="http://jaimeiniesta.com">blog</a> and <a href="http://twitter.com/jaimeiniesta">tweets</a>.
+<% end %>
diff --git a/railties/guides/source/credits.textile.erb b/railties/guides/source/credits.textile.erb
deleted file mode 100644
index 0c54049e1c..0000000000
--- a/railties/guides/source/credits.textile.erb
+++ /dev/null
@@ -1,60 +0,0 @@
-<% content_for :header_section do %>
-h2. Credits
-
-p. We'd like to thank the following people for their tireless contributions to this project.
-
-<% end %>
-
-<h3 class="section">Rails Documentation Team</h3>
-
-<%= author('Mike Gunderloy', 'mgunderloy') do %>
- Mike Gunderloy is a consultant with "ActionRails":http://www.actionrails.com. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at "A Fresh Cup":http://afreshcup.com and he "twitters":http://twitter.com/MikeG1 too much.
-<% end %>
-
-<%= author('Pratik Naik', 'lifo') do %>
- Pratik Naik is a Ruby on Rails consultant with "ActionRails":http://www.actionrails.com and also a member of the "Rails core team":http://rubyonrails.org/core. He maintains a blog at "has_many :bugs, :through => :rails":http://m.onkey.org and has an active "twitter account":http://twitter.com/lifo.
-<% end %>
-
-<%= author('Xavier Noria', 'fxn', 'fxn.png') do %>
- Xavier has been into Rails since 2005, he is currently a Rails consultant. Xavier is president of the <a href="http://www.srug.org/">Spanish Ruby Users Group</a> and has been involved in Rails in several ways. He enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Oh, he also "tweets":http://twitter.com/fxn!
-<% end %>
-
-<h3 class="section">Rails Guides Designers</h3>
-
-<%= author('Jason Zimdars', 'jz') do %>
- Jason Zimdars is an experienced creative director and web designer who has lead UI and UX design for numerous websites and web applications. You can see more of his design and writing at <a href="http://www.thinkcage.com/">Thinkcage.com</a> or follow him on <a href="http://twitter.com/JZ">Twitter</a>.
-<% end %>
-
-<h3 class="section">Rails Guides Authors</h3>
-
-<%= author('Frederick Cheung', 'fcheung') do %>
- Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at "spacevatican.org":http://www.spacevatican.org.
-<% end %>
-
-<%= author('Tore Darell', 'toretore') do %>
- Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog "Sneaky Abstractions":http://tore.darell.no.
-<% end %>
-
-<%= author('Jeff Dean', 'zilkey') do %>
- Jeff Dean is a software engineer with "Pivotal Labs":http://pivotallabs.com.
-<% end %>
-
-<%= author('Cássio Marques', 'cmarques') do %>
- Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at "/* CODIFICANDO */":http://cassiomarques.wordpress.com, which is mainly written in Portuguese, but will soon get a new section for posts with English translation.
-<% end %>
-
-<%= author('James Miller', 'bensie') do %>
- James Miller is a software developer for "JK Tech":http://www.jk-tech.com in San Diego, CA. Find me on GitHub, Gmail, Twitter, and Freenode as bensie.
-<% end %>
-
-<%= author('Emilio Tagua', 'miloops') do %>
- Emilio Tagua -- a.k.a. miloops -- is an Argentinian entrepreneur, developer, open source contributor and Rails evangelist. Cofounder of "Eventioz":http://eventioz.com. He has been using Rails since 2006 and contributing since early 2008. Can be found at gmail, twitter, freenode, everywhere as miloops.
-<% end %>
-
-<%= author('Heiko Webers', 'hawe') do %>
- Heiko Webers is the founder of "bauland42":http://www.bauland42.de, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the "Ruby on Rails Security Project":http://www.rorsecurity.info. After 10 years of desktop application development, Heiko has rarely looked back.
-<% end %>
-
-<%= author('Mikel Lindsaar', 'raasdnil') do %>
- Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby Mail gem and core contributor (he helped re-write ActionMailer's API). Mikel has a "blog":http://lindsaar.net/ and "tweets":http://twitter.com/raasdnil.
-<% end %>
diff --git a/railties/guides/source/debugging_rails_applications.textile b/railties/guides/source/debugging_rails_applications.textile
index cd0098d686..3eddf1a2b1 100644
--- a/railties/guides/source/debugging_rails_applications.textile
+++ b/railties/guides/source/debugging_rails_applications.textile
@@ -286,7 +286,7 @@ condition down finish list ps save thread var
continue edit frame method putl set tmate where
</shell>
-TIP: To view the help menu for any command use +help <command-name>+ in active debug mode. For example: _+help var+_
+TIP: To view the help menu for any command use +help &lt;command-name&gt;+ in active debug mode. For example: _+help var+_
The next command to learn is one of the most useful: +list+. You can also abbreviate ruby-debug commands by supplying just enough letters to distinguish them from other commands, so you can also use +l+ for the +list+ command.
@@ -704,6 +704,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/5
+* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":credits.html#jaimeiniesta
* November 3, 2008: Accepted for publication. Added RJS, memory leaks and plugins chapters by "Emilio Tagua":credits.html#miloops
* October 19, 2008: Copy editing pass by "Mike Gunderloy":credits.html#mgunderloy
* September 16, 2008: initial version by "Emilio Tagua":credits.html#miloops
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index d33bb4b4ff..fe0f8f1ac9 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -501,7 +501,7 @@ Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, pa
The +:prefix+ option is the key used to retrieve the hash of date components from the +params+ hash. Here it was set to +start_date+, if omitted it will default to +date+.
-h4. Model Object Helpers
+h4(#select-model-object-helpers). Model Object Helpers
+select_date+ does not work well with forms that update or create Active Record objects as Active Record expects each element of the +params+ hash to correspond to one attribute.
The model object helpers for dates and times submit parameters with special names, when Active Record sees parameters with such names it knows they must be combined with the other parameters and given to a constructor appropriate to the column type. For example:
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index c479c2fb20..9669f7f155 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -545,7 +545,7 @@ This view iterates over the contents of the +@posts+ array to display content an
* +link_to+ builds a hyperlink to a particular destination
* +edit_post_path+ is a helper that Rails provides as part of RESTful routing. You'll see a variety of these helpers for the different actions that the controller includes.
-NOTE. In previous versions of Rails, you had to use +<%=h post.name %>+ so that any HTML would be escaped before being inserted into the page. In Rails 3.0, this is now the default. To get unescaped HTML, you now use +<%= raw post.name %>+.
+NOTE. In previous versions of Rails, you had to use +&lt;%=h post.name %&gt;+ so that any HTML would be escaped before being inserted into the page. In Rails 3.0, this is now the default. To get unescaped HTML, you now use +&lt;%= raw post.name %&gt;+.
TIP: For more details on the rendering process, see "Layouts and Rendering in Rails":layouts_and_rendering.html.
@@ -597,7 +597,7 @@ The +new.html.erb+ view displays this empty Post to the user:
<%= link_to 'Back', posts_path %>
</erb>
-The +<%= render 'form' %>+ line is our first introduction to _partials_ in Rails. A partial is a snippet of HTML and Ruby code that can be reused in multiple locations. In this case, the form used to make a new post, is basically identical to a form used to edit a post, both have text fields for the name and title and a text area for the content with a button to make a new post or update the existing post.
+The +&lt;%= render 'form' %&gt;+ line is our first introduction to _partials_ in Rails. A partial is a snippet of HTML and Ruby code that can be reused in multiple locations. In this case, the form used to make a new post, is basically identical to a form used to edit a post, both have text fields for the name and title and a text area for the content with a button to make a new post or update the existing post.
If you take a look at +views/posts/_form.html.erb+ file, you will see the following:
@@ -1432,6 +1432,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
+* April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":credits.html#jaimeiniesta
* February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits:html#raasdnil
* January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits:html#raasdnil
* July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by "Mike Gunderloy":credits.html#mgunderloy
diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb
new file mode 100644
index 0000000000..8864b52325
--- /dev/null
+++ b/railties/guides/source/index.html.erb
@@ -0,0 +1,150 @@
+<% content_for :header_section do %>
+<h2>Ruby on Rails Guides</h2>
+
+<% if @edge %>
+<p>
+ These are <b>Edge Guides</b>, based on the current
+ <a href="http://github.com/rails/rails/tree/master">master branch</a>.
+</p>
+<p>
+ If you are looking for the ones for the stable version please check
+ <a href="http://guides.rubyonrails.org">http://guides.rubyonrails.org</a> instead.
+</p>
+<% end %>
+
+<p>
+ These guides are designed to make you immediately productive with Rails,
+ and to help you understand how all of the pieces fit together.
+</p>
+
+<% end %>
+
+<% content_for :index_section do %>
+<div id="subCol">
+ <dl>
+ <dd class="warning">Rails Guides are a result of the ongoing <a href="http://hackfest.rubyonrails.org">Guides hackfest</a>, and a work in progress.</dd>
+ <dd class="ticket">Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket.</dd>
+ </dl>
+</div>
+<% end %>
+
+<h3>Start Here</h3>
+
+<dl>
+<%= guide('Getting Started with Rails', 'getting_started.html') do %>
+ <p>Everything you need to know to install Rails and create your first application.</p>
+<% end %>
+</dl>
+
+<h3>Models</h3>
+
+<dl>
+<%= guide("Rails Database Migrations", 'migrations.html') do %>
+ <p>This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.</p>
+<% end %>
+
+<%= guide("Active Record Validations and Callbacks", 'activerecord_validations_callbacks.html') do %>
+ <p>This guide covers how you can use Active Record validations and callbacks.</p>
+<% end %>
+
+<%= guide("Active Record Associations", 'association_basics.html') do %>
+ <p>This guide covers all the associations provided by Active Record.</p>
+<% end %>
+
+<%= guide("Active Record Query Interface", 'active_record_querying.html') do %>
+ <p>This guide covers the database query interface provided by Active Record.</p>
+<% end %>
+</dl>
+
+<h3>Views</h3>
+
+<dl>
+<%= guide("Layouts and Rendering in Rails", 'layouts_and_rendering.html') do %>
+ <p>This guide covers the basic layout features of Action Controller and Action View, including rendering and redirecting, using content_for blocks, and working with partials.</p>
+<% end %>
+
+<%= guide("Action View Form Helpers", 'form_helpers.html', :ticket => 1) do %>
+ <p>Guide to using built in Form helpers.</p>
+<% end %>
+</dl>
+
+<h3>Controllers</h3>
+
+<dl>
+<%= guide("Action Controller Overview", 'action_controller_overview.html') do %>
+ <p>This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics.</p>
+<% end %>
+
+<%= guide("Rails Routing from the Outside In", 'routing.html') do %>
+ <p>This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here.</p>
+<% end %>
+</dl>
+
+<h3>Digging Deeper</h3>
+
+<dl>
+
+<%= guide("Rails on Rack", 'rails_on_rack.html') do %>
+ <p>This guide covers Rails integration with Rack and interfacing with other Rack components.</p>
+<% end %>
+
+<%= guide("Rails Internationalization API", 'i18n.html') do %>
+ <p>This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on.</p>
+<% end %>
+
+<%= guide("Action Mailer Basics", 'action_mailer_basics.html', :ticket => 25) do %>
+ <p>This guide describes how to use Action Mailer to send and receive emails.</p>
+<% end %>
+
+<%= guide("Testing Rails Applications", 'testing.html', :ticket => 8) do %>
+ <p>This is a rather comprehensive guide to doing both unit and functional tests in Rails. It covers everything from &quot;What is a test?&quot; to the testing APIs. Enjoy.</p>
+<% end %>
+
+<%= guide("Securing Rails Applications", 'security.html') do %>
+ <p>This guide describes common security problems in web applications and how to avoid them with Rails.</p>
+<% end %>
+
+<%= guide("Debugging Rails Applications", 'debugging_rails_applications.html') do %>
+ <p>This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening "behind the scenes" of your code.</p>
+<% end %>
+
+<%= guide("Performance Testing Rails Applications", 'performance_testing.html') do %>
+ <p>This guide covers the various ways of performance testing a Ruby on Rails application.</p>
+<% end %>
+
+<%= guide("The Basics of Creating Rails Plugins", 'plugins.html', :ticket => 32) do %>
+ <p>This guide covers how to build a plugin to extend the functionality of Rails.</p>
+<% end %>
+
+<%= guide("Configuring Rails Applications", 'configuring.html') do %>
+ <p>This guide covers the basic configuration settings for a Rails application.</p>
+<% end %>
+
+<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html', :ticket => 29) do %>
+ <p>This guide covers the command line tools and rake tasks provided by Rails.</p>
+<% end %>
+
+<%= guide("Caching with Rails", 'caching_with_rails.html', :ticket => 10) do %>
+ <p>Various caching techniques provided by Rails.</p>
+<% end %>
+
+<%= guide("Contributing to Rails", 'contributing_to_rails.html') do %>
+ <p>Rails is not &quot;somebody else's framework.&quot; This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>
+<% end %>
+</dl>
+
+<h3>Release Notes</h3>
+
+<dl>
+<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>
+ <p>Release notes for Rails 3.0.</p>
+<% end %>
+
+<%= guide("Ruby on Rails 2.3 Release Notes", '2_3_release_notes.html') do %>
+ <p>Release notes for Rails 2.3.</p>
+<% end %>
+
+<%= guide("Ruby on Rails 2.2 Release Notes", '2_2_release_notes.html') do %>
+ <p>Release notes for Rails 2.2.</p>
+<% end %>
+</dl>
diff --git a/railties/guides/source/index.textile.erb b/railties/guides/source/index.textile.erb
deleted file mode 100644
index 538fe48a38..0000000000
--- a/railties/guides/source/index.textile.erb
+++ /dev/null
@@ -1,139 +0,0 @@
-<% content_for :header_section do %>
-h2. Ruby on Rails Guides
-
-These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together. There are two different versions of the Guides site, and you should be sure to use the one that applies to your situation:
-
-* "Current Release version":http://guides.rubyonrails.org - based on Rails 2.3
-* "Edge version":http://edgeguides.rubyonrails.org - based on the current Rails "master branch":http://github.com/rails/rails/tree/master
-
-<% end %>
-
-<% content_for :index_section do %>
-<div id="subCol">
- <dl>
- <dd class="warning">Rails Guides are a result of the ongoing "Guides hackfest":http://hackfest.rubyonrails.org and a work in progress.</dd>
- <dd class="ticket">Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket.</dd>
- </dl>
-</div>
-<% end %>
-
-h3. Start Here
-
-<dl>
-<%= guide('Getting Started with Rails', 'getting_started.html') do %>
- Everything you need to know to install Rails and create your first application.
-<% end %>
-</dl>
-
-h3. Models
-
-<dl>
-<%= guide("Rails Database Migrations", 'migrations.html') do %>
- This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.
-<% end %>
-
-<%= guide("Active Record Validations and Callbacks", 'activerecord_validations_callbacks.html') do %>
- This guide covers how you can use Active Record validations and callbacks.
-<% end %>
-
-<%= guide("Active Record Associations", 'association_basics.html') do %>
- This guide covers all the associations provided by Active Record.
-<% end %>
-
-<%= guide("Active Record Query Interface", 'active_record_querying.html') do %>
- This guide covers the database query interface provided by Active Record.
-<% end %>
-</dl>
-
-h3. Views
-
-<dl>
-<%= guide("Layouts and Rendering in Rails", 'layouts_and_rendering.html') do %>
- This guide covers the basic layout features of Action Controller and Action View, including rendering and redirecting, using content_for blocks, and working with partials.
-<% end %>
-
-<%= guide("Action View Form Helpers", 'form_helpers.html', :ticket => 1) do %>
- Guide to using built in Form helpers.
-<% end %>
-</dl>
-
-h3. Controllers
-
-<dl>
-<%= guide("Action Controller Overview", 'action_controller_overview.html') do %>
- This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics.
-<% end %>
-
-<%= guide("Rails Routing from the Outside In", 'routing.html') do %>
- This guide covers the user-facing features of Rails routing. If you want to understand how to use routing in your own Rails applications, start here.
-<% end %>
-</dl>
-
-h3. Digging Deeper
-
-<dl>
-
-<%= guide("Rails on Rack", 'rails_on_rack.html') do %>
- This guide covers Rails integration with Rack and interfacing with other Rack components.
-<% end %>
-
-<%= guide("Rails Internationalization API", 'i18n.html') do %>
- This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on.
-<% end %>
-
-<%= guide("Action Mailer Basics", 'action_mailer_basics.html', :ticket => 25) do %>
- This guide describes how to use Action Mailer to send and receive emails.
-<% end %>
-
-<%= guide("Testing Rails Applications", 'testing.html', :ticket => 8) do %>
- This is a rather comprehensive guide to doing both unit and functional tests in Rails. It covers everything from “What is a test?” to the testing APIs. Enjoy.
-<% end %>
-
-<%= guide("Securing Rails Applications", 'security.html') do %>
- This guide describes common security problems in web applications and how to avoid them with Rails.
-<% end %>
-
-<%= guide("Debugging Rails Applications", 'debugging_rails_applications.html') do %>
- This guide describes how to debug Rails applications. It covers the different ways of achieving this and how to understand what is happening "behind the scenes" of your code.
-<% end %>
-
-<%= guide("Performance Testing Rails Applications", 'performance_testing.html') do %>
- This guide covers the various ways of performance testing a Ruby on Rails application.
-<% end %>
-
-<%= guide("The Basics of Creating Rails Plugins", 'plugins.html', :ticket => 32) do %>
- This guide covers how to build a plugin to extend the functionality of Rails.
-<% end %>
-
-<%= guide("Configuring Rails Applications", 'configuring.html') do %>
- This guide covers the basic configuration settings for a Rails application.
-<% end %>
-
-<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html', :ticket => 29) do %>
- This guide covers the command line tools and rake tasks provided by Rails.
-<% end %>
-
-<%= guide("Caching with Rails", 'caching_with_rails.html', :ticket => 10) do %>
- Various caching techniques provided by Rails.
-<% end %>
-
-<%= guide("Contributing to Rails", 'contributing_to_rails.html') do %>
- Rails is not "somebody else's framework." This guide covers a variety of ways that you can get involved in the ongoing development of Rails.
-<% end %>
-</dl>
-
-h3. Release Notes
-
-<dl>
-<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>
- Release notes for Rails 3.0.
-<% end %>
-
-<%= guide("Ruby on Rails 2.3 Release Notes", '2_3_release_notes.html') do %>
- Release notes for Rails 2.3.
-<% end %>
-
-<%= guide("Ruby on Rails 2.2 Release Notes", '2_2_release_notes.html') do %>
- Release notes for Rails 2.2.
-<% end %>
-</dl>
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index a21f1bbeed..b280101d25 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -1,19 +1,27 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><%= yield(:page_title) || 'Ruby on Rails guides' %></title>
-<link rel="stylesheet" type="text/css" href="files/stylesheets/style.css" />
-<link rel="stylesheet" type="text/css" href="files/stylesheets/syntax.css" />
-<link rel="stylesheet" type="text/css" href="files/stylesheets/print.css" media="print" />
+<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/syntax.css" />
+<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
-<script type="text/javascript" src="files/javascripts/guides.js"></script>
-<script type="text/javascript" src="files/javascripts/code_highlighter.js"></script>
-<script type="text/javascript" src="files/javascripts/highlighters.js"></script>
+<script type="text/javascript" src="javascripts/guides.js"></script>
+<script type="text/javascript" src="javascripts/code_highlighter.js"></script>
+<script type="text/javascript" src="javascripts/highlighters.js"></script>
</head>
<body class="guide">
+ <% if @edge %>
+ <div>
+ <img src="images/edge_badge.png" alt="edge-badge" id="edge-badge" />
+ </div>
+ <% end %>
<div id="topNav">
<div class="wrapper">
<strong>More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
@@ -101,7 +109,7 @@
<hr class="hide" />
<div id="footer">
<div class="wrapper">
- <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</a></p>
+ <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
</div>
</div>
diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile
index 2cb98e9ee6..d9781fc966 100644
--- a/railties/guides/source/layouts_and_rendering.textile
+++ b/railties/guides/source/layouts_and_rendering.textile
@@ -510,7 +510,7 @@ def show
end
</ruby>
-Make sure you use +and return+ and not +&& return+ because while the former will work, the latter will not due to operator precedence in the Ruby Language.
+Make sure you use +and return+ and not +&amp;&amp; return+ because while the former will work, the latter will not due to operator precedence in the Ruby Language.
Note that the implicit render done by ActionController detects if +render+ has been called, and thus avoids this error. Therefore, the following will work without errors:
@@ -747,7 +747,7 @@ You can even use dynamic paths such as +cache/#{current_site}/main/display+.
h5. Linking to CSS Files with +stylesheet_link_tag+
-The +stylesheet_link_tag+ helper returns an HTML +<link>+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.cs+:
+The +stylesheet_link_tag+ helper returns an HTML +&lt;link&gt;+ tag for each source provided. Rails looks in +public/stylesheets+ for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include +public/stylesheets/main.cs+:
<erb>
<%= stylesheet_link_tag "main" %>
@@ -1197,6 +1197,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/15
+* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":credits.html#jaimeiniesta
* January 25, 2010: Rails 3.0 Update by "Mikel Lindsaar":credits.html#raasdnil
* December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates
* December 27, 2008: Information on new rendering defaults by "Mike Gunderloy":credits.html#mgunderloy
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index 5c760a5966..f74b68b0ef 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -213,11 +213,11 @@ h4. Understanding the Output
Performance tests generate different outputs inside +tmp/performance+ directory depending on their mode and metric.
-h5. Benchmarking
+h5(#output-benchmarking). Benchmarking
In benchmarking mode, performance tests generate two types of outputs:
-h6. Command Line
+h6(#output-command-line). Command Line
This is the primary form of output in benchmarking mode. Example:
@@ -258,7 +258,7 @@ measurement,created_at,app,rails,ruby,platform
0.00771250000000012,2009-01-09T15:46:03Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0
</shell>
-h5. Profiling
+h5(#output-profiling). Profiling
In profiling mode, you can choose from four types of output.
@@ -330,7 +330,7 @@ h5. Apply the Patch
h5. Configure and Install
-The following will install ruby in your home directory's +/rubygc+ directory. Make sure to replace +<homedir>+ with a full patch to your actual home directory.
+The following will install ruby in your home directory's +/rubygc+ directory. Make sure to replace +&lt;homedir&gt;+ with a full patch to your actual home directory.
<shell>
[lifo@null ruby-version]$ ./configure --prefix=/<homedir>/rubygc
diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index 2db421aa91..74c8ee2df9 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -35,14 +35,14 @@ h4. Create the Basic Application
The examples in this guide require that you have a working rails application. To create a simple rails app execute:
-<pre>
+<shell>
gem install rails
rails yaffle_guide
cd yaffle_guide
rails generate scaffold bird name:string
rake db:migrate
rails server
-</pre>
+</shell>
Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails app before continuing.
@@ -56,22 +56,22 @@ Rails ships with a plugin generator which creates a basic plugin skeleton. Pass
This creates a plugin in 'vendor/plugins' including an 'init.rb' and 'README' as well as standard 'lib', 'task', and 'test' directories.
Examples:
-<pre>
+<shell>
rails generate plugin yaffle
rails generate plugin yaffle --with-generator
-</pre>
+</shell>
To get more detailed help on the plugin generator, type +rails generate plugin+.
Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the +--with-generator+ option now:
-<pre>
+<shell>
rails generate plugin yaffle --with-generator
-</pre>
+</shell>
You should see the following output:
-<pre>
+<shell>
create vendor/plugins/yaffle/lib
create vendor/plugins/yaffle/tasks
create vendor/plugins/yaffle/test
@@ -89,20 +89,20 @@ create vendor/plugins/yaffle/generators/yaffle
create vendor/plugins/yaffle/generators/yaffle/templates
create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb
create vendor/plugins/yaffle/generators/yaffle/USAGE
-</pre>
+</shell>
h4. Organize Your Files
To make it easy to organize your files and to make the plugin more compatible with GemPlugins, start out by altering your file system to look like this:
-<pre>
+<shell>
|-- lib
| |-- yaffle
| `-- yaffle.rb
`-- rails
|
`-- init.rb
-</pre>
+</shell>
*vendor/plugins/yaffle/init.rb*
@@ -124,7 +124,7 @@ h4. Test Setup
*vendor/plugins/yaffle/test/database.yml:*
-<pre>
+<yaml>
sqlite:
:adapter: sqlite
:dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db
@@ -146,7 +146,7 @@ mysql:
:username: root
:password: password
:database: yaffle_plugin_test
-</pre>
+</yaml>
For this guide you'll need 2 tables/models, Hickwalls and Wickwalls, so add the following:
@@ -239,10 +239,10 @@ end
To run this, go to the plugin directory and run +rake+:
-<pre>
+<shell>
cd vendor/plugins/yaffle
rake
-</pre>
+</shell>
You should see output like:
@@ -1511,4 +1511,5 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213/tickets/32-update-plugins-guide
+* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":credits.html#jaimeiniesta
* November 17, 2008: Major revision by Jeff Dean
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index 8cf084494b..0cf8c45761 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -65,7 +65,7 @@ RESTful routes take advantage of the built-in REST orientation of Rails to wrap
resources :books
</ruby>
-h4. Named Routes
+h4(#quick-tour-named-routes). Named Routes
Named routes give you very readable links in your code, as well as handling incoming requests. Here's a typical named route:
@@ -79,7 +79,7 @@ If you're coming from Rails 2, this route will be equivalent to:
map.login '/login', :controller => 'sessions', :action => 'new'
</ruby>
-You will also notice that +sessions#new+ is a shorthand for +:controller => 'sessions', :action => 'new'+. By declaring a named route such as this, you can use +login_path+ or +login_url+ in your controllers and views to generate the URLs for this route.
+You will also notice that +sessions#new+ is a shorthand for +:controller => 'sessions', :action => 'new'+. By declaring a named route such as this, you can use +login_path+ or +login_url+ in your controllers and views to generate the URLs for this route. A RESTful generates named routes without the need to explicitly generate a named route via +as+ key.
h4. Nested Routes
@@ -91,7 +91,7 @@ resources :assemblies do
end
</ruby>
-h4. Regular Routes
+h4(#quick-tour-regular-routes). Regular Routes
In many applications, you'll also see non-RESTful routing, which explicitly connects the parts of a URL to a particular action. For example,
@@ -215,8 +215,7 @@ Although the conventions of RESTful routing are likely to be sufficient for many
* +:controller+
* +:singular+
-* +:requirements+
-* +:conditions+
+* +:constraints+
* +:as+
* +:path_names+
* +:only+
@@ -257,13 +256,7 @@ If you use controller namespaces, you need to be aware of a subtlety in the Rail
TIP: If you want to guarantee that a link goes to a top-level controller, use a preceding slash to anchor the controller name: +&lt;%= link_to "show", {:controller => "/photos", :action => "show"} %&gt;+
-You can also specify a controller namespace with the +:namespace+ option instead of a path:
-
-<ruby>
-resources :adminphotos, :namespace => "admin", :controller => "photos"
-</ruby>
-
-This can be especially useful when map multiple namespaced routes together using +namespace+ block by:
+You can also specify a controller namespace with the +namespace+ method instead of a path. This can be especially useful when mapping multiple namespaced routes together:
<ruby>
namespace :admin do
@@ -285,20 +278,16 @@ resources :teeth, :singular => "tooth"
TIP: Depending on the other code in your application, you may prefer to add additional rules to the +Inflector+ class instead.
-h5. Using +:requirements+
+h5. Using +:constraints+
-You can use the +:requirements+ option in a RESTful route to impose a format on the implied +:id+ parameter in the singular routes. For example:
+You can use the +:constraints+ option in a RESTful route to impose a format on the implied parameter in routes. For example:
<ruby>
-resources :photos, :requirements => {:id => /[A-Z][A-Z][0-9]+/}
+resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}
</ruby>
This declaration constrains the +:id+ parameter to match the supplied regular expression. So, in this case, +/photos/1+ would no longer be recognized by this route, but +/photos/RR27+ would.
-h5. Using +:conditions+
-
-Conditions in Rails routing are currently used only to set the HTTP verb for individual routes. Although in theory you can set this for RESTful routes, in practice there is no good reason to do so. (You'll learn more about conditions in the discussion of classic routing later in this guide.)
-
h5. Using +:as+
The +:as+ option lets you override the normal naming for the actual generated paths. For example:
@@ -343,37 +332,15 @@ TIP: If you find yourself wanting to change this option uniformly for all of you
config.action_controller.resources_path_names = { :new => 'make', :edit => 'change' }
</ruby>
-h5. Using +:path_prefix+
-
-The +:path_prefix+ option lets you add additional parameters that will be prefixed to the recognized paths. For example, suppose each photo in your application belongs to a particular photographer. In that case, you might declare this route:
-
-<ruby>
-resources :photos, :path_prefix => '/photographers/:photographer_id'
-</ruby>
-
-Routes recognized by this entry would include:
-
-<pre>
-/photographers/1/photos/2
-/photographers/1/photos
-</pre>
-
-NOTE: In most cases, it's simpler to recognize URLs of this sort by creating nested resources, as discussed in the next section.
-
-NOTE: You can also use +:path_prefix+ with non-RESTful routes.
-
h5. Using +:name_prefix+
You can use the :name_prefix option to avoid collisions between routes. This is most useful when you have two resources with the same name that use +:path_prefix+ to map differently. For example:
<ruby>
-resources :photos, :path_prefix => '/photographers/:photographer_id',
- :name_prefix => 'photographer_'
-resources :photos, :path_prefix => '/agencies/:agency_id',
- :name_prefix => 'agency_'
+resources :photos :name_prefix => 'photographer'
</ruby>
-This combination will give you route helpers such as +photographer_photos_path+ and +agency_edit_photo_path+ to use in your code.
+This combination will give you route helpers such as +photographer_photos_path+ to use in your code.
NOTE: You can also use +:name_prefix+ with non-RESTful routes.
@@ -395,8 +362,6 @@ resources :photos, :except => :destroy
In this case, all of the normal routes except the route for +destroy+ (a +DELETE+ request to +/photos/<em>id</em>+) will be generated.
-In addition to an action or a list of actions, you can also supply the special symbols +:all+ or +:none+ to the +:only+ and +:except+ options.
-
TIP: If your application has many RESTful routes, using +:only+ and +:except+ to generate only the routes that you actually need can cut down on memory use and speed up the routing process.
h4. Nested Resources
@@ -421,8 +386,6 @@ resources :magazines do
end
</ruby>
-TIP: Further below you'll learn about a convenient shortcut for this construct:<br/>+resources :magazines, :has_many => :ads+
-
In addition to the routes for magazines, this declaration will also create routes for ads, each of which requires the specification of a magazine in the URL:
|_.HTTP verb|_.URL |_.controller|_.action |_.used for|
@@ -437,7 +400,7 @@ In addition to the routes for magazines, this declaration will also create route
This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+.
-h5. Using +:name_prefix+
+h5(#nested-name-prefix). Using +:name_prefix+
The +:name_prefix+ option overrides the automatically-generated prefix in nested route helpers. For example,
@@ -447,38 +410,7 @@ resources :magazines do
end
</ruby>
-This will create routing helpers such as +periodical_ads_url+ and +periodical_edit_ad_path+. You can even use +:name_prefix+ to suppress the prefix entirely:
-
-<ruby>
-resources :magazines do
- resources :ads, :name_prefix => nil
-end
-</ruby>
-
-This will create routing helpers such as +ads_url+ and +edit_ad_path+. Note that calling these will still require supplying an article id:
-
-<ruby>
-ads_url(@magazine)
-edit_ad_path(@magazine, @ad)
-</ruby>
-
-h5. Using +:has_one+ and +:has_many+
-
-The +:has_one+ and +:has_many+ options provide a succinct notation for simple nested routes. Use +:has_one+ to nest a singleton resource, or +:has_many+ to nest a plural resource:
-
-<ruby>
-resources :photos, :has_one => :photographer, :has_many => [:publications, :versions]
-</ruby>
-
-This has the same effect as this set of declarations:
-
-<ruby>
-resources :photos do
- resource :photographer
- resources :publications
- resources :versions
-end
-</ruby>
+This will create routing helpers such as +periodical_ads_url+ and +periodical_edit_ad_path+.
h5. Limits to Nesting
@@ -492,7 +424,7 @@ resources :publishers do
end
</ruby>
-However, without the use of +name_prefix => nil+, deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as
+Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as
<pre>
/publishers/1/magazines/2/photos/3
@@ -524,11 +456,7 @@ This will enable recognition of (among others) these routes:
/photos/3 ==> photo_path(3)
</pre>
-With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with. If you like, you can combine shallow nesting with the +:has_one+ and +:has_many+ options:
-
-<ruby>
-resources :publishers, :has_many => { :magazines => :photos }, :shallow => true
-</ruby>
+With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.
h4. Route Generation from Arrays
@@ -556,19 +484,25 @@ This format is especially useful when you might not know until runtime which of
h4. Namespaced Resources
-It's possible to do some quite complex things by combining +:path_prefix+ and +:name_prefix+. For example, you can use the combination of these two options to move administrative resources to their own folder in your application:
+It's possible to do some quite complex things by combining +scope+ and +:name_prefix+. For example, you can use the combination of these two options to move administrative resources to their own folder in your application:
<ruby>
-resources :photos, :path_prefix => 'admin', :controller => 'admin/photos'
-resources :tags, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_tags'
-resources :ratings, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_ratings'
+scope 'admin' do
+ resources :photos, :name_prefix => "admin", :controller => 'admin/photos'
+ scope 'photos' do
+ resources :tags, :name_prefix => 'admin_photo', :controller => 'admin/photo_tags'
+ resources :ratings, :name_prefix => 'admin_photo', :controller => 'admin/photo_ratings'
+ end
+end
</ruby>
The good news is that if you find yourself using this level of complexity, you can stop. Rails supports _namespaced resources_ to make placing resources in their own folder a snap. Here's the namespaced version of those same three routes:
<ruby>
namespace :admin do
- resources :photos, :has_many => { :tags, :ratings }
+ resources :photos do
+ resources :tags, :ratings
+ end
end
</ruby>
@@ -592,7 +526,7 @@ end
This will enable Rails to recognize URLs such as +/photos/1/preview+ using the GET HTTP verb, and route them to the preview action of the Photos controller. It will also create the +preview_photo_url+ and +preview_photo_path+ route helpers.
-Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, +delete+, or +any+ here. If you don't have multiple +member+ route, you can also passing +:on+ to the routing.
+Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, or +delete+ here. If you don't have multiple +member+ route, you can also passing +:on+ to the routing.
<ruby>
resources :photos do
@@ -649,7 +583,7 @@ When you set up a regular route, you supply a series of symbols that Rails maps
match ':controller(/:action(/:id))'
</ruby>
-If an incoming request of +/photos/show/1+ is processed by this route (because it hasn't matched any previous route in the file), then the result will be to invoke the +show+ action of the +Photos+ controller, and to make the final parameter (1) available as +params[:id]+.
+If an incoming request of +/photos/show/1+ is processed by this route (because it hasn't matched any previous route in the file), then the result will be to invoke the +show+ action of the +Photos+ controller, and to make the final parameter (1) available as +params[:id]+. This route will also route the incoming request of +/photos+ to PhotosController, since +:action+ and +:id+ are optional parameters, denoted by parenthesis.
h4. Wildcard Components
@@ -709,12 +643,12 @@ match 'logout' => 'sessions#destroy', :as => :logout
This will do two things. First, requests to +/logout+ will be sent to the +destroy+ action of the +Sessions+ controller. Second, Rails will maintain the +logout_path+ and +logout_url+ helpers for use within your code.
-h4. Route Requirements
+h4. Route Constraints
-You can use the +:requirements+ option to enforce a format for any parameter in a route:
+You can use the +:constraints+ option to enforce a format for any parameter in a route:
<ruby>
-match 'photo/:id' => 'photos#show', :requirements => { :id => /[A-Z]\d{5}/ }
+match 'photo/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }
</ruby>
This route would respond to URLs such as +/photo/A12345+. You can more succinctly express the same route this way:
@@ -723,16 +657,6 @@ This route would respond to URLs such as +/photo/A12345+. You can more succinctl
match 'photo/:id' => 'photos#show', :id => /[A-Z]\d{5}/
</ruby>
-h4. Route Conditions
-
-Route conditions (introduced with the +:conditions+ option) are designed to implement restrictions on routes. Currently, the only supported restriction is +:method+:
-
-<ruby>
-match 'photo/:id' => 'photos#show', :conditions => { :method => :get }
-</ruby>
-
-As with conditions in RESTful routes, you can specify +:get+, +:post+, +:put+, +:delete+, or +:any+ for the acceptable method.
-
h4. Route Globbing
Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example
@@ -743,20 +667,6 @@ match 'photo/*other' => 'photos#unknown'
This route would match +photo/12+ or +/photo/long/path/to/12+ equally well, creating an array of path segments as the value of +params[:other]+.
-h4. Route Options
-
-You can use +:with_options+ to simplify defining groups of similar routes:
-
-<ruby>
-map.with_options :controller => 'photo' do |photo|
- photo.list '', :action => 'index'
- photo.delete ':id/delete', :action => 'delete'
- photo.edit ':id/edit', :action => 'edit'
-end
-</ruby>
-
-The importance of +map.with_options+ has declined with the introduction of RESTful routes.
-
h3. Formats and +respond_to+
There's one more way in which routing can do different things depending on differences in the incoming HTTP request: by issuing a response that corresponds to what the request specifies that it will accept. In Rails routing, you can control this with the special +:format+ parameter in the route.
@@ -899,6 +809,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/3
+* April 2, 2010: Updated guide to match new Routing DSL in Rails 3, by Rizwan Reza
* Febuary 1, 2010: Modifies the routing documentation to match new routing DSL in Rails 3, by Prem Sichanugrist
* October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes, by "Mike Gunderloy":credits.html#mgunderloy
* September 23, 2008: Added section on namespaced controllers and routing, by "Mike Gunderloy":credits.html#mgunderloy
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index b62ff8cb38..1ddf094d18 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -611,7 +611,7 @@ h4. SQL Injection
-- _Thanks to clever methods, this is hardly a problem in most Rails applications. However, this is a very devastating and common attack in web applications, so it is important to understand the problem._
-h5. Introduction
+h5(#sql-injection-introduction). Introduction
SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:
@@ -668,7 +668,7 @@ The result won't be a list of projects (because there is no project with an empt
Also, the second query renames some columns with the AS statement so that the web application displays the values from the user table. Be sure to update your Rails "to at least 2.1.1":http://www.rorsecurity.info/2008/09/08/sql-injection-issue-in-limit-and-offset-parameter/.
-h5. Countermeasures
+h5(#sql-injection-countermeasures). Countermeasures
Ruby on Rails has a built in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. <em class="highlight">Using +Model.find(id)+ or +Model.find_by_some thing(something)+ automatically applies this countermeasure</em>. But in SQL fragments, especially <em class="highlight">in conditions fragments (+:conditions => "..."+), the +connection.execute()+ or +Model.find_by_sql()+ methods, it has to be applied manually</em>.
@@ -760,7 +760,7 @@ http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode
<script src=http://www.securitylab.ru/test/sc.js></script><!--
</plain>
-h6. Countermeasures
+h6(#html-injection-countermeasures). Countermeasures
_(highlight)It is very important to filter malicious input, but it is also important to escape the output of the web application_.
@@ -850,7 +850,7 @@ In the end, he got a 4 KB worm, which he injected into his profile page.
The "moz-binding":http://www.securiteam.com/securitynews/5LP051FHPE.html CSS property proved to be another way to introduce JavaScript in CSS in Gecko-based browsers (Firefox, for example).
-h5. Countermeasures
+h5(#css-injection-countermeasures). Countermeasures
This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. _(highlight)If you want to allow custom colours or images, you can allow the user to choose them and build the CSS in the web application_. Use Rails' +sanitize()+ method as a model for a whitelist CSS filter, if you really need one.
@@ -879,7 +879,7 @@ RedCloth.new("<a href='javascript:alert(1)'>hello</a>", [:filter_html]).to_html
# => "<p><a href="javascript:alert(1)">hello</a></p>"
</ruby>
-h5. Countermeasures
+h5(#textile-injection-countermeasures). Countermeasures
It is recommended to _(highlight)use RedCloth in combination with a whitelist input filter_, as described in the countermeasures against XSS section.
diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile
index ac9fb4276e..b1eee0ccb9 100644
--- a/railties/guides/source/testing.textile
+++ b/railties/guides/source/testing.textile
@@ -411,7 +411,7 @@ NOTE: +assert_valid(record)+ has been deprecated. Please use +assert(record.vali
|_.Assertion |_.Purpose|
|+assert_valid(record)+ |Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.|
|+assert_difference(expressions, difference = 1, message = nil) {...}+ |Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.|
-|+assert_no_difference(expressions, message = nil, &block)+ |Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.|
+|+assert_no_difference(expressions, message = nil, &amp;block)+ |Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.|
|+assert_recognizes(expected_options, path, extras={}, message=nil)+ |Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.|
|+assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)+ |Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.|
|+assert_response(type, message = nil)+ |Asserts that the response comes with a specific status code. You can specify +:success+ to indicate 200, +:redirect+ to indicate 300-399, +:missing+ to indicate 404, or +:error+ to match the 500-599 range|
@@ -940,6 +940,7 @@ h3. Changelog
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/8
+* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":credits.html#jaimeiniesta
* November 13, 2008: Revised based on feedback from Pratik Naik by "Akshay Surve":credits.html#asurve (not yet approved for publication)
* October 14, 2008: Edit and formatting pass by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
* October 12, 2008: First draft by "Akshay Surve":credits.html#asurve (not yet approved for publication)