railties 3.0.0.beta2 → 3.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -2
- data/guides/{images → assets/images}/belongs_to.png +0 -0
- data/guides/{images → assets/images}/book_icon.gif +0 -0
- data/guides/{images → assets/images}/bullet.gif +0 -0
- data/guides/{images → assets/images}/challenge.png +0 -0
- data/guides/{images → assets/images}/chapters_icon.gif +0 -0
- data/guides/{images → assets/images}/check_bullet.gif +0 -0
- data/guides/{images → assets/images}/credits_pic_blank.gif +0 -0
- data/guides/{images → assets/images}/csrf.png +0 -0
- data/guides/{images → assets/images}/customized_error_messages.png +0 -0
- data/guides/{images → assets/images}/edge_badge.png +0 -0
- data/guides/{images → assets/images}/error_messages.png +0 -0
- data/guides/{images → assets/images}/feature_tile.gif +0 -0
- data/guides/{images → assets/images}/footer_tile.gif +0 -0
- data/guides/{images → assets/images}/fxn.png +0 -0
- data/guides/{images → assets/images}/grey_bullet.gif +0 -0
- data/guides/{images → assets/images}/habtm.png +0 -0
- data/guides/{images → assets/images}/has_many.png +0 -0
- data/guides/{images → assets/images}/has_many_through.png +0 -0
- data/guides/{images → assets/images}/has_one.png +0 -0
- data/guides/{images → assets/images}/has_one_through.png +0 -0
- data/guides/{images → assets/images}/header_backdrop.png +0 -0
- data/guides/{images → assets/images}/header_tile.gif +0 -0
- data/guides/{images → assets/images}/i18n/demo_localized_pirate.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translated_en.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translated_pirate.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translation_missing.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_untranslated.png +0 -0
- data/guides/{images → assets/images}/icons/README +0 -0
- data/guides/{images → assets/images}/icons/callouts/1.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/10.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/11.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/12.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/13.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/14.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/15.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/2.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/3.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/4.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/5.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/6.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/7.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/8.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/9.png +0 -0
- data/guides/{images → assets/images}/icons/caution.png +0 -0
- data/guides/{images → assets/images}/icons/example.png +0 -0
- data/guides/{images → assets/images}/icons/home.png +0 -0
- data/guides/{images → assets/images}/icons/important.png +0 -0
- data/guides/{images → assets/images}/icons/next.png +0 -0
- data/guides/{images → assets/images}/icons/note.png +0 -0
- data/guides/{images → assets/images}/icons/prev.png +0 -0
- data/guides/{images → assets/images}/icons/tip.png +0 -0
- data/guides/{images → assets/images}/icons/up.png +0 -0
- data/guides/{images → assets/images}/icons/warning.png +0 -0
- data/guides/assets/images/jaimeiniesta.jpg +0 -0
- data/guides/{images → assets/images}/nav_arrow.gif +0 -0
- data/guides/{images → assets/images}/polymorphic.png +0 -0
- data/guides/{images → assets/images}/posts_index.png +0 -0
- data/guides/{images → assets/images}/rails_guides_logo.gif +0 -0
- data/guides/{images → assets/images}/rails_logo_remix.gif +0 -0
- data/guides/{images → assets/images}/rails_welcome.png +0 -0
- data/guides/{images → assets/images}/session_fixation.png +0 -0
- data/guides/{images → assets/images}/tab_grey.gif +0 -0
- data/guides/{images → assets/images}/tab_info.gif +0 -0
- data/guides/{images → assets/images}/tab_note.gif +0 -0
- data/guides/{images → assets/images}/tab_red.gif +0 -0
- data/guides/{images → assets/images}/tab_yellow.gif +0 -0
- data/guides/{images → assets/images}/tab_yellow.png +0 -0
- data/guides/{images → assets/images}/validation_error_messages.png +0 -0
- data/guides/{files → assets}/javascripts/code_highlighter.js +0 -0
- data/guides/{files → assets}/javascripts/guides.js +0 -0
- data/guides/{files → assets}/javascripts/highlighters.js +0 -0
- data/guides/{files → assets}/stylesheets/main.css +26 -15
- data/guides/{files → assets}/stylesheets/print.css +0 -0
- data/guides/{files → assets}/stylesheets/reset.css +0 -0
- data/guides/{files → assets}/stylesheets/style.css +0 -0
- data/guides/{files → assets}/stylesheets/syntax.css +0 -0
- data/guides/rails_guides/generator.rb +79 -29
- data/guides/rails_guides/helpers.rb +2 -2
- data/guides/rails_guides/indexer.rb +24 -11
- data/guides/source/2_2_release_notes.textile +1 -1
- data/guides/source/3_0_release_notes.textile +27 -1
- data/guides/source/action_controller_overview.textile +7 -7
- data/guides/source/action_view_overview.textile +15 -15
- data/guides/source/active_record_querying.textile +4 -3
- data/guides/source/active_support_core_extensions.textile +6 -6
- data/guides/source/activerecord_validations_callbacks.textile +1 -1
- data/guides/source/association_basics.textile +83 -82
- data/guides/source/command_line.textile +16 -12
- data/guides/source/configuring.textile +1 -1
- data/guides/source/contribute.textile +1 -1
- data/guides/source/contributing_to_rails.textile +3 -4
- data/guides/source/credits.html.erb +64 -0
- data/guides/source/debugging_rails_applications.textile +2 -1
- data/guides/source/form_helpers.textile +15 -13
- data/guides/source/getting_started.textile +9 -8
- data/guides/source/index.html.erb +154 -0
- data/guides/source/initialization.textile +4138 -0
- data/guides/source/layout.html.erb +15 -7
- data/guides/source/layouts_and_rendering.textile +6 -5
- data/guides/source/nested_model_forms.textile +3 -3
- data/guides/source/performance_testing.textile +4 -4
- data/guides/source/plugins.textile +15 -14
- data/guides/source/rails_on_rack.textile +1 -1
- data/guides/source/routing.textile +379 -490
- data/guides/source/security.textile +5 -5
- data/guides/source/testing.textile +3 -2
- data/lib/rails.rb +7 -2
- data/lib/rails/application.rb +9 -2
- data/lib/rails/application/configuration.rb +19 -10
- data/lib/rails/application/finisher.rb +4 -0
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/{bin/rails → lib/rails/cli.rb} +0 -0
- data/lib/rails/commands/runner.rb +1 -1
- data/lib/rails/configuration.rb +12 -0
- data/lib/rails/engine.rb +6 -10
- data/lib/rails/engine/configuration.rb +2 -3
- data/lib/rails/generators.rb +1 -6
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -7
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +10 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb +2 -0
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/rails/app/app_generator.rb +1 -1
- data/lib/rails/generators/rails/app/templates/Gemfile +2 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +1 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +14 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb +4 -1
- data/lib/rails/generators/rails/app/templates/config/boot.rb +5 -13
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cookie_verification_secret.rb.tt → secret_token.rb.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -3
- data/lib/rails/generators/rails/app/templates/public/index.html +2 -1
- data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +41 -32
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb → test_helper.rb.tt} +2 -0
- data/lib/rails/generators/rails/model/USAGE +15 -0
- data/lib/rails/generators/rails/stylesheets/templates/scaffold.css +3 -8
- data/lib/rails/paths.rb +17 -5
- data/lib/rails/plugin.rb +1 -1
- data/lib/rails/railtie.rb +3 -25
- data/lib/rails/test_unit/testing.rake +11 -7
- data/lib/rails/version.rb +1 -1
- data/lib/rails/webrick_server.rb +2 -2
- metadata +93 -92
- data/guides/source/credits.textile.erb +0 -60
- data/guides/source/index.textile.erb +0 -139
- data/lib/rails/generators/erb/scaffold/templates/layout.html.erb +0 -17
- data/lib/rails/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
@@ -18,12 +18,12 @@ h3. Command Line Basics
|
|
18
18
|
|
19
19
|
There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you'll probably use them are:
|
20
20
|
|
21
|
-
* rails console
|
22
|
-
* rails server
|
23
|
-
* rake
|
24
|
-
* rails generate
|
25
|
-
* rails dbconsole
|
26
|
-
* rails app_name
|
21
|
+
* <tt>rails console</tt>
|
22
|
+
* <tt>rails server</tt>
|
23
|
+
* <tt>rake</tt>
|
24
|
+
* <tt>rails generate</tt>
|
25
|
+
* <tt>rails dbconsole</tt>
|
26
|
+
* <tt>rails app_name</tt>
|
27
27
|
|
28
28
|
Let's create a simple Rails application to step through each of these commands in context.
|
29
29
|
|
@@ -246,9 +246,13 @@ $ rake db:migrate
|
|
246
246
|
|
247
247
|
INFO: Let's talk about unit tests. Unit tests are code that tests and makes assertions about code. In unit testing, we take a little part of code, say a method of a model, and test its inputs and outputs. Unit tests are your friend. The sooner you make peace with the fact that your quality of life will drastically increase when you unit test your code, the better. Seriously. We'll make one in a moment.
|
248
248
|
|
249
|
-
Let's see the interface Rails created for us.
|
249
|
+
Let's see the interface Rails created for us.
|
250
250
|
|
251
|
-
|
251
|
+
<shell>
|
252
|
+
$ rails server
|
253
|
+
</shell>
|
254
|
+
|
255
|
+
Go to your browser and open "http://localhost:3000/high_scores":http://localhost:3000/high_scores, now we can create new high scores (55,160 on Space Invaders!)
|
252
256
|
|
253
257
|
h4. +rails console+
|
254
258
|
|
@@ -260,12 +264,12 @@ h4. +rails dbconsole+
|
|
260
264
|
|
261
265
|
h4. +rails plugin+
|
262
266
|
|
263
|
-
The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. Let's walk through installing a plugin. You can call the sub-command
|
267
|
+
The +rails plugin+ command simplifies plugin management; think a miniature version of the Gem utility. Let's walk through installing a plugin. You can call the sub-command +discover+, which sifts through repositories looking for plugins, or call +source+ to add a specific repository of plugins, or you can specify the plugin location directly.
|
268
|
+
|
269
|
+
Let's say you're creating a website for a client who wants a small accounting system. Every event having to do with money must be logged, and must never be deleted. Wouldn't it be great if we could override the behavior of a model to never actually take its record out of the database, but instead, just set a field?
|
264
270
|
|
265
|
-
|
271
|
+
There is such a thing! The plugin we're installing is called +acts_as_paranoid+, and it lets models implement a +deleted_at+ column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things.
|
266
272
|
|
267
|
-
There is such a thing! The plugin we're installing is called "acts_as_paranoid", and it lets models implement a "deleted_at" column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things.
|
268
|
-
==================================================================================
|
269
273
|
<shell>
|
270
274
|
$ rails plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid
|
271
275
|
+ ./CHANGELOG
|
@@ -183,7 +183,7 @@ There are only a few configuration options for Action View, starting with four o
|
|
183
183
|
|
184
184
|
* +config.action_view.warn_cache_misses+ tells Rails to display a warning whenever an action results in a cache miss on your view paths. The default is +false+.
|
185
185
|
|
186
|
-
* +config.action_view.field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is <tt>Proc.new{ |html_tag, instance| "
|
186
|
+
* +config.action_view.field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is <tt>Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" }</tt>
|
187
187
|
|
188
188
|
* +config.action_view.default_form_builder+ tells Rails which form builder to use by default. The default is +ActionView::Helpers::FormBuilder+.
|
189
189
|
|
@@ -9,7 +9,7 @@ h3. How to Contribute?
|
|
9
9
|
* We have an open commit policy: anyone is welcome to contribute, but you'll need to ask for commit access.
|
10
10
|
* PM lifo at "GitHub":http://github.com asking for "docrails":http://github.com/lifo/docrails/tree/master commit access.
|
11
11
|
* Guides are written in Textile, and reside at railties/guides/source in the docrails project.
|
12
|
-
*
|
12
|
+
* Assets are stored in the +railties/guides/assets+ directory.
|
13
13
|
* Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile
|
14
14
|
* Sample output : "Active Record Associations":association_basics.html
|
15
15
|
* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory.
|
@@ -208,7 +208,7 @@ h4. Follow the Coding Conventions
|
|
208
208
|
Rails follows a simple set of coding style conventions.
|
209
209
|
|
210
210
|
* Two spaces, no tabs
|
211
|
-
* Prefer
|
211
|
+
* Prefer +&&+/+||+ over +and+/+or+
|
212
212
|
* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+
|
213
213
|
* Follow the conventions you see used in the source already
|
214
214
|
|
@@ -273,7 +273,6 @@ h3. Changelog
|
|
273
273
|
|
274
274
|
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/64
|
275
275
|
|
276
|
+
* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
276
277
|
* August 1, 2009: Updates/amplifications by "Mike Gunderloy":credits.html#mgunderloy
|
277
|
-
* March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy
|
278
|
-
|
279
|
-
|
278
|
+
* March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<% content_for :page_title do %>
|
2
|
+
Ruby on Rails Guides: Credits
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :header_section do %>
|
6
|
+
<h2>Credits</h2>
|
7
|
+
|
8
|
+
<p>We'd like to thank the following people for their tireless contributions to this project.</p>
|
9
|
+
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<h3 class="section">Rails Documentation Team</h3>
|
13
|
+
|
14
|
+
<%= author('Mike Gunderloy', 'mgunderloy') do %>
|
15
|
+
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.
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<%= author('Pratik Naik', 'lifo') do %>
|
19
|
+
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 => :rails</a> and has an active <a href="http://twitter.com/lifo">twitter account</a>.
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= author('Xavier Noria', 'fxn', 'fxn.png') do %>
|
23
|
+
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 "fxn".
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<h3 class="section">Rails Guides Designers</h3>
|
27
|
+
|
28
|
+
<%= author('Jason Zimdars', 'jz') do %>
|
29
|
+
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>.
|
30
|
+
<% end %>
|
31
|
+
|
32
|
+
<h3 class="section">Rails Guides Authors</h3>
|
33
|
+
|
34
|
+
<%= author('Frederick Cheung', 'fcheung') do %>
|
35
|
+
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>.
|
36
|
+
<% end %>
|
37
|
+
|
38
|
+
<%= author('Tore Darell', 'toretore') do %>
|
39
|
+
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>.
|
40
|
+
<% end %>
|
41
|
+
|
42
|
+
<%= author('Jeff Dean', 'zilkey') do %>
|
43
|
+
Jeff Dean is a software engineer with <a href="http://pivotallabs.com">Pivotal Labs</a>.
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
<%= author('Cássio Marques', 'cmarques') do %>
|
47
|
+
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.
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
<%= author('James Miller', 'bensie') do %>
|
51
|
+
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 "bensie".
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<%= author('Emilio Tagua', 'miloops') do %>
|
55
|
+
Emilio Tagua —a.k.a. miloops— 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 "miloops".
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<%= author('Heiko Webers', 'hawe') do %>
|
59
|
+
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.
|
60
|
+
<% end %>
|
61
|
+
|
62
|
+
<%= author('Mikel Lindsaar', 'raasdnil') do %>
|
63
|
+
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>.
|
64
|
+
<% end %>
|
@@ -286,7 +286,7 @@ condition down finish list ps save thread var
|
|
286
286
|
continue edit frame method putl set tmate where
|
287
287
|
</shell>
|
288
288
|
|
289
|
-
TIP: To view the help menu for any command use +help
|
289
|
+
TIP: To view the help menu for any command use +help <command-name>+ in active debug mode. For example: _+help var+_
|
290
290
|
|
291
291
|
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.
|
292
292
|
|
@@ -704,6 +704,7 @@ h3. Changelog
|
|
704
704
|
|
705
705
|
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/5
|
706
706
|
|
707
|
+
* April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
707
708
|
* November 3, 2008: Accepted for publication. Added RJS, memory leaks and plugins chapters by "Emilio Tagua":credits.html#miloops
|
708
709
|
* October 19, 2008: Copy editing pass by "Mike Gunderloy":credits.html#mgunderloy
|
709
710
|
* September 16, 2008: initial version by "Emilio Tagua":credits.html#miloops
|
@@ -21,7 +21,7 @@ h3. Dealing with Basic Forms
|
|
21
21
|
The most basic form helper is +form_tag+.
|
22
22
|
|
23
23
|
<erb>
|
24
|
-
|
24
|
+
<%= form_tag do %>
|
25
25
|
Form contents
|
26
26
|
<% end %>
|
27
27
|
</erb>
|
@@ -59,14 +59,14 @@ To create this form you will use +form_tag+, +label_tag+, +text_field_tag+, and
|
|
59
59
|
A basic search form
|
60
60
|
|
61
61
|
<html>
|
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
|
</html>
|
68
68
|
|
69
|
-
TIP: +search_path+ can be a named route specified in "routes.rb": <
|
69
|
+
TIP: +search_path+ can be a named route specified in "routes.rb": <br /><tt>map.search "search", :controller => "search"</tt>
|
70
70
|
|
71
71
|
The above view code will result in the following markup:
|
72
72
|
|
@@ -222,7 +222,7 @@ end
|
|
222
222
|
The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks like this:
|
223
223
|
|
224
224
|
<erb>
|
225
|
-
|
225
|
+
<%= form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>
|
226
226
|
<%= f.text_field :title %>
|
227
227
|
<%= f.text_area :body, :size => "60x12" %>
|
228
228
|
<%= submit_tag "Create" %>
|
@@ -253,7 +253,7 @@ The helper methods called on the form builder are identical to the model object
|
|
253
253
|
You can create a similar binding without actually creating +<form>+ tags with the +fields_for+ helper. This is useful for editing additional model objects with the same form. For example if you had a Person model with an associated ContactDetail model you could create a form for creating both like so:
|
254
254
|
|
255
255
|
<erb>
|
256
|
-
|
256
|
+
<%= form_for :person, @person, :url => { :action => "create" } do |person_form| %>
|
257
257
|
<%= person_form.text_field :name %>
|
258
258
|
<% fields_for @person.contact_detail do |contact_details_form| %>
|
259
259
|
<%= contact_details_form.text_field :phone_number %>
|
@@ -429,7 +429,7 @@ As with other helpers, if you were to use the +select+ helper on a form builder
|
|
429
429
|
<%= f.select(:city_id, ...) %>
|
430
430
|
</erb>
|
431
431
|
|
432
|
-
WARNING: If you are using +select+ (or similar helpers such as +collection_select+, +select_tag+) to set a +belongs_to+ association you must pass the name of the foreign key (in the example above +city_id+), not the name of association itself. If you specify +city+ instead of +city_id+ Active Record will raise an error along the lines of <
|
432
|
+
WARNING: If you are using +select+ (or similar helpers such as +collection_select+, +select_tag+) to set a +belongs_to+ association you must pass the name of the foreign key (in the example above +city_id+), not the name of association itself. If you specify +city+ instead of +city_id+ Active Record will raise an error along the lines of <tt> ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750) </tt> when you pass the +params+ hash to +Person.new+ or +update_attributes+. Another way of looking at this is that form helpers only edit attributes. You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly. You may wish to consider the use of +attr_protected+ and +attr_accessible+. For further details on this, see the "Ruby On Rails Security Guide":security.html#_mass_assignment.
|
433
433
|
|
434
434
|
h4. Option Tags from a Collection of Arbitrary Objects
|
435
435
|
|
@@ -501,7 +501,7 @@ Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, pa
|
|
501
501
|
|
502
502
|
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+.
|
503
503
|
|
504
|
-
h4. Model Object Helpers
|
504
|
+
h4(#select-model-object-helpers). Model Object Helpers
|
505
505
|
|
506
506
|
+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.
|
507
507
|
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:
|
@@ -554,11 +554,11 @@ A common task is uploading some sort of file, whether it's a picture of a person
|
|
554
554
|
The following two forms both upload a file.
|
555
555
|
|
556
556
|
<erb>
|
557
|
-
|
557
|
+
<%= form_tag({:action => :upload}, :multipart => true) do %>
|
558
558
|
<%= file_field_tag 'picture' %>
|
559
559
|
<% end %>
|
560
560
|
|
561
|
-
|
561
|
+
<%= form_for @person, :html => {:multipart => true} do |f| %>
|
562
562
|
<%= f.file_field :picture %>
|
563
563
|
<% end %>
|
564
564
|
</erb>
|
@@ -591,7 +591,7 @@ h3. Customizing Form Builders
|
|
591
591
|
As mentioned previously the object yielded by +form_for+ and +fields_for+ is an instance of FormBuilder (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way you can also subclass FormBuilder and add the helpers there. For example
|
592
592
|
|
593
593
|
<erb>
|
594
|
-
|
594
|
+
<%= form_for @person do |f| %>
|
595
595
|
<%= text_field_with_label f, :first_name %>
|
596
596
|
<% end %>
|
597
597
|
</erb>
|
@@ -599,7 +599,7 @@ As mentioned previously the object yielded by +form_for+ and +fields_for+ is an
|
|
599
599
|
can be replaced with
|
600
600
|
|
601
601
|
<erb>
|
602
|
-
|
602
|
+
<%= form_for @person, :builder => LabellingFormBuilder do |f| %>
|
603
603
|
<%= f.text_field :first_name %>
|
604
604
|
<% end %>
|
605
605
|
</erb>
|
@@ -631,7 +631,7 @@ action for a Person model, +params[:model]+ would usually be a hash of all the a
|
|
631
631
|
|
632
632
|
Fundamentally HTML forms don't know about any sort of structured data, all they generate is name–value pairs, where pairs are just plain strings. The arrays and hashes you see in your application are the result of some parameter naming conventions that Rails uses.
|
633
633
|
|
634
|
-
TIP: You may find you can try out examples in this section faster by using the console to directly invoke Rails' parameter parser. For example <
|
634
|
+
TIP: You may find you can try out examples in this section faster by using the console to directly invoke Rails' parameter parser. For example <tt> ActionController::UrlEncodedPairParser.parse_query_parameters "name=fred&phone=0123456789" # => {"name"=>"fred", "phone"=>"0123456789"} </tt>
|
635
635
|
|
636
636
|
h4. Basic Structures
|
637
637
|
|
@@ -694,7 +694,7 @@ The previous sections did not use the Rails form helpers at all. While you can c
|
|
694
694
|
You might want to render a form with a set of edit fields for each of a person's addresses. For example:
|
695
695
|
|
696
696
|
<erb>
|
697
|
-
|
697
|
+
<%= form_for @person do |person_form| %>
|
698
698
|
<%= person_form.text_field :name %>
|
699
699
|
<% for address in @person.addresses %>
|
700
700
|
<% person_form.fields_for address, :index => address do |address_form|%>
|
@@ -762,6 +762,8 @@ h3. Changelog
|
|
762
762
|
|
763
763
|
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/1
|
764
764
|
|
765
|
+
* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
766
|
+
|
765
767
|
h3. Authors
|
766
768
|
|
767
769
|
* Mislav Marohnić <mislav.marohnic@gmail.com>
|
@@ -545,7 +545,7 @@ This view iterates over the contents of the +@posts+ array to display content an
|
|
545
545
|
* +link_to+ builds a hyperlink to a particular destination
|
546
546
|
* +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.
|
547
547
|
|
548
|
-
NOTE. In previous versions of Rails, you had to use
|
548
|
+
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 %>+.
|
549
549
|
|
550
550
|
TIP: For more details on the rendering process, see "Layouts and Rendering in Rails":layouts_and_rendering.html.
|
551
551
|
|
@@ -597,12 +597,12 @@ The +new.html.erb+ view displays this empty Post to the user:
|
|
597
597
|
<%= link_to 'Back', posts_path %>
|
598
598
|
</erb>
|
599
599
|
|
600
|
-
The
|
600
|
+
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.
|
601
601
|
|
602
602
|
If you take a look at +views/posts/_form.html.erb+ file, you will see the following:
|
603
603
|
|
604
604
|
<erb>
|
605
|
-
|
605
|
+
<%= form_for(@post) do |f| %>
|
606
606
|
<%= f.error_messages %>
|
607
607
|
|
608
608
|
<div class="field">
|
@@ -906,7 +906,7 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+
|
|
906
906
|
</p>
|
907
907
|
|
908
908
|
<h2>Add a comment:</h2>
|
909
|
-
|
909
|
+
<%= form_for([@post, @post.comments.build]) do |f| %>
|
910
910
|
<%= f.error_messages %>
|
911
911
|
|
912
912
|
<div class="field">
|
@@ -974,7 +974,7 @@ Once we have made the new comment, we send the user back to the +post_path(@post
|
|
974
974
|
<% end %>
|
975
975
|
|
976
976
|
<h2>Add a comment:</h2>
|
977
|
-
|
977
|
+
<%= form_for([@post, @post.comments.build]) do |f| %>
|
978
978
|
<%= f.error_messages %>
|
979
979
|
|
980
980
|
<div class="field">
|
@@ -1041,7 +1041,7 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f
|
|
1041
1041
|
:collection => @post.comments %>
|
1042
1042
|
|
1043
1043
|
<h2>Add a comment:</h2>
|
1044
|
-
|
1044
|
+
<%= form_for([@post, @post.comments.build]) do |f| %>
|
1045
1045
|
<%= f.error_messages %>
|
1046
1046
|
|
1047
1047
|
<div class="field">
|
@@ -1070,7 +1070,7 @@ h4. Rendering a Partial Form
|
|
1070
1070
|
Lets also move that new comment section out to it's own partial, again, you create a file +app/views/comments/_form.html.erb+ and in it you put:
|
1071
1071
|
|
1072
1072
|
<erb>
|
1073
|
-
|
1073
|
+
<%= form_for([@post, @post.comments.build]) do |f| %>
|
1074
1074
|
<%= f.error_messages %>
|
1075
1075
|
|
1076
1076
|
<div class="field">
|
@@ -1278,7 +1278,7 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag:
|
|
1278
1278
|
|
1279
1279
|
<erb>
|
1280
1280
|
<% @post.tags.build %>
|
1281
|
-
|
1281
|
+
<%= form_for(@post) do |post_form| %>
|
1282
1282
|
<%= post_form.error_messages %>
|
1283
1283
|
|
1284
1284
|
<div class="field">
|
@@ -1432,6 +1432,7 @@ h3. Changelog
|
|
1432
1432
|
|
1433
1433
|
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2
|
1434
1434
|
|
1435
|
+
* April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
|
1435
1436
|
* February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits:html#raasdnil
|
1436
1437
|
* January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits:html#raasdnil
|
1437
1438
|
* July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by "Mike Gunderloy":credits.html#mgunderloy
|
@@ -0,0 +1,154 @@
|
|
1
|
+
<% content_for :page_title do %>
|
2
|
+
Ruby on Rails Guides
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :header_section do %>
|
6
|
+
<h2>Ruby on Rails Guides</h2>
|
7
|
+
|
8
|
+
<% if @edge %>
|
9
|
+
<p>
|
10
|
+
These are <b>Edge Guides</b>, based on the current
|
11
|
+
<a href="http://github.com/rails/rails/tree/master">master branch</a>.
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
If you are looking for the ones for the stable version please check
|
15
|
+
<a href="http://guides.rubyonrails.org">http://guides.rubyonrails.org</a> instead.
|
16
|
+
</p>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
These guides are designed to make you immediately productive with Rails,
|
21
|
+
and to help you understand how all of the pieces fit together.
|
22
|
+
</p>
|
23
|
+
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<% content_for :index_section do %>
|
27
|
+
<div id="subCol">
|
28
|
+
<dl>
|
29
|
+
<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>
|
30
|
+
<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>
|
31
|
+
</dl>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<h3>Start Here</h3>
|
36
|
+
|
37
|
+
<dl>
|
38
|
+
<%= guide('Getting Started with Rails', 'getting_started.html') do %>
|
39
|
+
<p>Everything you need to know to install Rails and create your first application.</p>
|
40
|
+
<% end %>
|
41
|
+
</dl>
|
42
|
+
|
43
|
+
<h3>Models</h3>
|
44
|
+
|
45
|
+
<dl>
|
46
|
+
<%= guide("Rails Database Migrations", 'migrations.html') do %>
|
47
|
+
<p>This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner.</p>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
<%= guide("Active Record Validations and Callbacks", 'activerecord_validations_callbacks.html') do %>
|
51
|
+
<p>This guide covers how you can use Active Record validations and callbacks.</p>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<%= guide("Active Record Associations", 'association_basics.html') do %>
|
55
|
+
<p>This guide covers all the associations provided by Active Record.</p>
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<%= guide("Active Record Query Interface", 'active_record_querying.html') do %>
|
59
|
+
<p>This guide covers the database query interface provided by Active Record.</p>
|
60
|
+
<% end %>
|
61
|
+
</dl>
|
62
|
+
|
63
|
+
<h3>Views</h3>
|
64
|
+
|
65
|
+
<dl>
|
66
|
+
<%= guide("Layouts and Rendering in Rails", 'layouts_and_rendering.html') do %>
|
67
|
+
<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>
|
68
|
+
<% end %>
|
69
|
+
|
70
|
+
<%= guide("Action View Form Helpers", 'form_helpers.html', :ticket => 1) do %>
|
71
|
+
<p>Guide to using built in Form helpers.</p>
|
72
|
+
<% end %>
|
73
|
+
</dl>
|
74
|
+
|
75
|
+
<h3>Controllers</h3>
|
76
|
+
|
77
|
+
<dl>
|
78
|
+
<%= guide("Action Controller Overview", 'action_controller_overview.html') do %>
|
79
|
+
<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>
|
80
|
+
<% end %>
|
81
|
+
|
82
|
+
<%= guide("Rails Routing from the Outside In", 'routing.html') do %>
|
83
|
+
<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>
|
84
|
+
<% end %>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
<h3>Digging Deeper</h3>
|
88
|
+
|
89
|
+
<dl>
|
90
|
+
|
91
|
+
<%= guide("Rails on Rack", 'rails_on_rack.html') do %>
|
92
|
+
<p>This guide covers Rails integration with Rack and interfacing with other Rack components.</p>
|
93
|
+
<% end %>
|
94
|
+
|
95
|
+
<%= guide("Rails Internationalization API", 'i18n.html') do %>
|
96
|
+
<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>
|
97
|
+
<% end %>
|
98
|
+
|
99
|
+
<%= guide("Action Mailer Basics", 'action_mailer_basics.html', :ticket => 25) do %>
|
100
|
+
<p>This guide describes how to use Action Mailer to send and receive emails.</p>
|
101
|
+
<% end %>
|
102
|
+
|
103
|
+
<%= guide("Testing Rails Applications", 'testing.html', :ticket => 8) do %>
|
104
|
+
<p>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.</p>
|
105
|
+
<% end %>
|
106
|
+
|
107
|
+
<%= guide("Securing Rails Applications", 'security.html') do %>
|
108
|
+
<p>This guide describes common security problems in web applications and how to avoid them with Rails.</p>
|
109
|
+
<% end %>
|
110
|
+
|
111
|
+
<%= guide("Debugging Rails Applications", 'debugging_rails_applications.html') do %>
|
112
|
+
<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>
|
113
|
+
<% end %>
|
114
|
+
|
115
|
+
<%= guide("Performance Testing Rails Applications", 'performance_testing.html') do %>
|
116
|
+
<p>This guide covers the various ways of performance testing a Ruby on Rails application.</p>
|
117
|
+
<% end %>
|
118
|
+
|
119
|
+
<%= guide("The Basics of Creating Rails Plugins", 'plugins.html', :ticket => 32) do %>
|
120
|
+
<p>This guide covers how to build a plugin to extend the functionality of Rails.</p>
|
121
|
+
<% end %>
|
122
|
+
|
123
|
+
<%= guide("Configuring Rails Applications", 'configuring.html') do %>
|
124
|
+
<p>This guide covers the basic configuration settings for a Rails application.</p>
|
125
|
+
<% end %>
|
126
|
+
|
127
|
+
<%= guide("Rails Command Line Tools and Rake tasks", 'command_line.html', :ticket => 29) do %>
|
128
|
+
<p>This guide covers the command line tools and rake tasks provided by Rails.</p>
|
129
|
+
<% end %>
|
130
|
+
|
131
|
+
<%= guide("Caching with Rails", 'caching_with_rails.html', :ticket => 10) do %>
|
132
|
+
<p>Various caching techniques provided by Rails.</p>
|
133
|
+
<% end %>
|
134
|
+
|
135
|
+
<%= guide("Contributing to Rails", 'contributing_to_rails.html') do %>
|
136
|
+
<p>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.</p>
|
137
|
+
<% end %>
|
138
|
+
</dl>
|
139
|
+
|
140
|
+
<h3>Release Notes</h3>
|
141
|
+
|
142
|
+
<dl>
|
143
|
+
<%= guide("Ruby on Rails 3.0 Release Notes", '3_0_release_notes.html') do %>
|
144
|
+
<p>Release notes for Rails 3.0.</p>
|
145
|
+
<% end %>
|
146
|
+
|
147
|
+
<%= guide("Ruby on Rails 2.3 Release Notes", '2_3_release_notes.html') do %>
|
148
|
+
<p>Release notes for Rails 2.3.</p>
|
149
|
+
<% end %>
|
150
|
+
|
151
|
+
<%= guide("Ruby on Rails 2.2 Release Notes", '2_2_release_notes.html') do %>
|
152
|
+
<p>Release notes for Rails 2.2.</p>
|
153
|
+
<% end %>
|
154
|
+
</dl>
|