railties 3.0.20 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +36 -49
  2. data/README.rdoc +2 -1
  3. data/guides/assets/stylesheets/fixes.css +16 -0
  4. data/guides/rails_guides.rb +2 -2
  5. data/guides/rails_guides/generator.rb +8 -3
  6. data/guides/rails_guides/textile_extensions.rb +4 -2
  7. data/guides/source/2_2_release_notes.textile +3 -3
  8. data/guides/source/2_3_release_notes.textile +2 -2
  9. data/guides/source/3_0_release_notes.textile +14 -14
  10. data/guides/source/action_controller_overview.textile +54 -79
  11. data/guides/source/action_mailer_basics.textile +39 -9
  12. data/guides/source/action_view_overview.textile +257 -211
  13. data/guides/source/active_record_basics.textile +1 -1
  14. data/guides/source/active_record_querying.textile +217 -27
  15. data/guides/source/active_record_validations_callbacks.textile +94 -25
  16. data/guides/source/active_support_core_extensions.textile +109 -77
  17. data/guides/source/ajax_on_rails.textile +15 -150
  18. data/guides/source/api_documentation_guidelines.textile +12 -12
  19. data/guides/source/association_basics.textile +74 -60
  20. data/guides/source/caching_with_rails.textile +59 -60
  21. data/guides/source/command_line.textile +46 -47
  22. data/guides/source/configuring.textile +55 -37
  23. data/guides/source/contribute.textile +7 -7
  24. data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
  25. data/guides/source/credits.html.erb +3 -3
  26. data/guides/source/debugging_rails_applications.textile +59 -46
  27. data/guides/source/form_helpers.textile +76 -31
  28. data/guides/source/generators.textile +39 -40
  29. data/guides/source/getting_started.textile +73 -94
  30. data/guides/source/i18n.textile +64 -58
  31. data/guides/source/index.html.erb +3 -3
  32. data/guides/source/initialization.textile +634 -3284
  33. data/guides/source/layout.html.erb +6 -7
  34. data/guides/source/layouts_and_rendering.textile +59 -60
  35. data/guides/source/migrations.textile +63 -59
  36. data/guides/source/nested_model_forms.textile +2 -2
  37. data/guides/source/performance_testing.textile +16 -16
  38. data/guides/source/plugins.textile +236 -1280
  39. data/guides/source/rails_application_templates.textile +37 -29
  40. data/guides/source/rails_on_rack.textile +4 -9
  41. data/guides/source/routing.textile +96 -75
  42. data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
  43. data/guides/source/security.textile +57 -30
  44. data/guides/source/testing.textile +26 -24
  45. data/guides/w3c_validator.rb +2 -2
  46. data/lib/rails.rb +1 -7
  47. data/lib/rails/application.rb +46 -76
  48. data/lib/rails/application/bootstrap.rb +6 -11
  49. data/lib/rails/application/configuration.rb +43 -40
  50. data/lib/rails/application/finisher.rb +16 -4
  51. data/lib/rails/application/railties.rb +6 -24
  52. data/lib/rails/application/routes_reloader.rb +45 -0
  53. data/lib/rails/backtrace_cleaner.rb +1 -1
  54. data/lib/rails/cli.rb +7 -5
  55. data/lib/rails/commands.rb +27 -2
  56. data/lib/rails/commands/application.rb +14 -1
  57. data/lib/rails/commands/benchmarker.rb +3 -1
  58. data/lib/rails/commands/dbconsole.rb +2 -2
  59. data/lib/rails/commands/destroy.rb +3 -1
  60. data/lib/rails/commands/generate.rb +3 -1
  61. data/lib/rails/commands/plugin.rb +2 -7
  62. data/lib/rails/commands/plugin_new.rb +10 -0
  63. data/lib/rails/commands/profiler.rb +3 -1
  64. data/lib/rails/commands/server.rb +4 -0
  65. data/lib/rails/configuration.rb +8 -81
  66. data/lib/rails/console/app.rb +2 -2
  67. data/lib/rails/engine.rb +460 -78
  68. data/lib/rails/engine/configuration.rb +46 -49
  69. data/lib/rails/engine/railties.rb +33 -0
  70. data/lib/rails/generators.rb +11 -5
  71. data/lib/rails/generators/actions.rb +2 -27
  72. data/lib/rails/generators/app_base.rb +216 -0
  73. data/lib/rails/generators/base.rb +3 -2
  74. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
  75. data/lib/rails/generators/generated_attribute.rb +2 -1
  76. data/lib/rails/generators/migration.rb +6 -2
  77. data/lib/rails/generators/named_base.rb +79 -3
  78. data/lib/rails/generators/rails/app/app_generator.rb +44 -209
  79. data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
  80. data/lib/rails/generators/rails/app/templates/README +2 -2
  81. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  82. data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
  83. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
  84. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
  85. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  86. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  87. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  88. data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
  89. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
  90. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
  91. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
  92. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
  94. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
  95. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
  96. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  97. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
  98. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  99. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  100. data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
  101. data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
  102. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  103. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  104. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  105. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  106. data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
  107. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  108. data/lib/rails/generators/rails/assets/USAGE +20 -0
  109. data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
  110. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  111. data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
  112. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  113. data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
  114. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  115. data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
  116. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
  117. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  118. data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
  119. data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
  120. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
  121. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  122. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
  123. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
  124. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
  125. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  126. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  127. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
  128. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  129. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  130. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  131. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  132. data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
  133. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  134. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  135. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  136. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
  137. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  138. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  139. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
  140. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  141. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  142. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
  143. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  144. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
  145. data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
  146. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
  147. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
  148. data/lib/rails/generators/resource_helpers.rb +3 -3
  149. data/lib/rails/generators/test_case.rb +2 -20
  150. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
  151. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
  152. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
  153. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
  154. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
  155. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
  156. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
  157. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
  158. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
  159. data/lib/rails/info.rb +0 -1
  160. data/lib/rails/paths.rb +119 -65
  161. data/lib/rails/plugin.rb +18 -19
  162. data/lib/rails/rack/log_tailer.rb +1 -1
  163. data/lib/rails/railtie.rb +50 -47
  164. data/lib/rails/railtie/configurable.rb +20 -10
  165. data/lib/rails/railtie/configuration.rb +20 -19
  166. data/lib/rails/source_annotation_extractor.rb +5 -5
  167. data/lib/rails/tasks.rb +1 -0
  168. data/lib/rails/tasks/assets.rake +10 -0
  169. data/lib/rails/tasks/documentation.rake +2 -8
  170. data/lib/rails/tasks/engine.rake +69 -0
  171. data/lib/rails/tasks/framework.rake +4 -21
  172. data/lib/rails/tasks/misc.rake +1 -1
  173. data/lib/rails/tasks/routes.rake +2 -1
  174. data/lib/rails/test_help.rb +17 -1
  175. data/lib/rails/test_unit/railtie.rb +1 -1
  176. data/lib/rails/test_unit/testing.rake +8 -3
  177. data/lib/rails/version.rb +3 -3
  178. metadata +128 -100
  179. checksums.yaml +0 -7
  180. data/lib/rails/application/configurable.rb +0 -19
  181. data/lib/rails/console/sandbox.rb +0 -6
  182. data/lib/rails/deprecation.rb +0 -41
  183. data/lib/rails/engine/configurable.rb +0 -25
  184. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
  185. data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
  186. data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
  187. data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
  188. data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
  189. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
  190. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
  191. data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
  192. data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
  193. data/lib/rails/info_routes.rb +0 -3
@@ -19,7 +19,7 @@ h4. Walkthrough to Generating a Mailer
19
19
  h5. Create the Mailer
20
20
 
21
21
  <shell>
22
- rails generate mailer UserMailer
22
+ $ rails generate mailer UserMailer
23
23
  create app/mailers/user_mailer.rb
24
24
  invoke erb
25
25
  create app/views/user_mailer
@@ -27,7 +27,7 @@ invoke test_unit
27
27
  create test/functional/user_mailer_test.rb
28
28
  </shell>
29
29
 
30
- So we got the mailer, the fixtures, and the tests.
30
+ So we got the mailer, the views, and the tests.
31
31
 
32
32
  h5. Edit the Mailer
33
33
 
@@ -120,7 +120,7 @@ Now that we have a user model to play with, we will just edit the +app/controlle
120
120
  <ruby>
121
121
  class UsersController < ApplicationController
122
122
  # POST /users
123
- # POST /users.xml
123
+ # POST /users.json
124
124
  def create
125
125
  @user = User.new(params[:user])
126
126
 
@@ -130,10 +130,10 @@ class UsersController < ApplicationController
130
130
  UserMailer.welcome_email(@user).deliver
131
131
 
132
132
  format.html { redirect_to(@user, :notice => 'User was successfully created.') }
133
- format.xml { render :xml => @user, :status => :created, :location => @user }
133
+ format.json { render :json => @user, :status => :created, :location => @user }
134
134
  else
135
135
  format.html { render :action => "new" }
136
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
136
+ format.json { render :json => @user.errors, :status => :unprocessable_entity }
137
137
  end
138
138
  end
139
139
  end
@@ -198,7 +198,7 @@ Adding attachments has been simplified in Action Mailer 3.0.
198
198
  attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
199
199
  </ruby>
200
200
 
201
- NOTE: Mail will automatically Base64 encode an attachment, if you want something different, pre encode your content and pass in the encoded content and encoding in a +Hash+ to the +attachments+ method.
201
+ NOTE: Mail will automatically Base64 encode an attachment, if you want something different, pre-encode your content and pass in the encoded content and encoding in a +Hash+ to the +attachments+ method.
202
202
 
203
203
  * Pass the file name and specify headers and content and Action Mailer and Mail will use the settings you pass in.
204
204
 
@@ -240,6 +240,36 @@ end
240
240
  :class => 'photos' %>
241
241
  </erb>
242
242
 
243
+ h5. Sending Email To Multiple Recipients
244
+
245
+ It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the <tt>:to</tt> key. The <tt>to:</tt> key however expects a string so you have join the list of recipients using a comma.
246
+
247
+ <ruby>
248
+ class AdminMailer < ActionMailer::Base
249
+ default :to => Admin.all.map(&:email).join(", "),
250
+ :from => "notification@example.com"
251
+
252
+ def new_registration(user)
253
+ @user = user
254
+ mail(:subject => "New User Signup: #{@user.email}")
255
+ end
256
+ end
257
+ </ruby>
258
+
259
+ h5. Sending Email With Name
260
+
261
+ Sometimes you wish to show the name of the person instead of just their email address when they receive the email. The trick to doing that is
262
+ to format the email address in the format <tt>"Name &lt;email&gt;"</tt>.
263
+
264
+ <ruby>
265
+ def welcome_email(user)
266
+ @user = user
267
+ email_with_name = "#{@user.name} <#{@user.email}>"
268
+ mail(:to => email_with_name,
269
+ :subject => "Welcome to My Awesome Site")
270
+ end
271
+ </ruby>
272
+
243
273
  h4. Mailer Views
244
274
 
245
275
  Mailer views are located in the +app/views/name_of_mailer_class+ directory. The specific mailer view is known to the class because its name is the same as the mailer method. In our example from above, our mailer view for the +welcome_email+ method will be in +app/views/user_mailer/welcome_email.html.erb+ for the HTML version and +welcome_email.text.erb+ for the plain text version.
@@ -371,7 +401,7 @@ The above will send a multipart email with an attachment, properly nested with t
371
401
 
372
402
  h3. Receiving Emails
373
403
 
374
- Receiving and parsing emails with Action Mailer can be a rather complex endeavour. Before your email reaches your Rails app, you would have had to configure your system to somehow forward emails to your app, which needs to be listening for that. So, to receive emails in your Rails app you'll need:
404
+ Receiving and parsing emails with Action Mailer can be a rather complex endeavour. Before your email reaches your Rails app, you would have had to configure your system to somehow forward emails to your app, which needs to be listening for that. So, to receive emails in your Rails app you'll need to:
375
405
 
376
406
  * Implement a +receive+ method in your mailer.
377
407
 
@@ -413,8 +443,8 @@ The following configuration options are best made in one of the environment file
413
443
  |smtp_settings|Allows detailed configuration for :smtp delivery method:<ul><li>:address - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li>:port - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>:domain - If you need to specify a HELO domain, you can do it here.</li><li>:user_name - If your mail server requires authentication, set the username in this setting.</li><li>:password - If your mail server requires authentication, set the password in this setting.</li><li>:authentication - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5.</li></ul>|
414
444
  |sendmail_settings|Allows you to override options for the :sendmail delivery method.<ul><li>:location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.</li><li>:arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.</li></ul>|
415
445
  |raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.|
416
- |delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.|
417
- |perform_deliveries|Determines whether deliver_* methods are actually carried out. By default they are, but this can be turned off to help functional testing.|
446
+ |delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.|
447
+ |perform_deliveries|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
418
448
  |deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
419
449
 
420
450
  h4. Example Action Mailer Configuration
@@ -20,7 +20,28 @@ Note: Some features of Action View are tied to Active Record, but that doesn't m
20
20
 
21
21
  h3. Using Action View with Rails
22
22
 
23
- TODO...
23
+ For each controller there is an associated directory in the <tt>app/views</tt> directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
24
+
25
+ Let's take a look at what Rails does by default when creating a new resource using the scaffold generator:
26
+
27
+ <shell>
28
+ $ rails generate scaffold post
29
+ [...]
30
+ invoke scaffold_controller
31
+ create app/controllers/posts_controller.rb
32
+ invoke erb
33
+ create app/views/posts
34
+ create app/views/posts/index.html.erb
35
+ create app/views/posts/edit.html.erb
36
+ create app/views/posts/show.html.erb
37
+ create app/views/posts/new.html.erb
38
+ create app/views/posts/_form.html.erb
39
+ [...]
40
+ </shell>
41
+
42
+ There is a naming convention for views in Rails. Typically, the views share their name with the associated controller action, as you can see above.
43
+ For example, the index controller action of the <tt>posts_controller.rb</tt> will use the <tt>index.html.erb</tt> view file in the <tt>app/views/posts</tt> directory.
44
+ The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference. Later on this guide you can find a more detailed documentation of each one of this three components.
24
45
 
25
46
  h3. Using Action View outside of Rails
26
47
 
@@ -29,8 +50,8 @@ Action View works well with Action Record, but it can also be used with other Ru
29
50
  Let's start by ensuring that you have the Action Pack and Rack gems installed:
30
51
 
31
52
  <shell>
32
- gem install actionpack
33
- gem install rack
53
+ $ gem install actionpack
54
+ $ gem install rack
34
55
  </shell>
35
56
 
36
57
  Now we'll create a simple "Hello World" application that uses the +titleize+ method provided by Active Support.
@@ -52,7 +73,7 @@ Rack::Handler::Mongrel.run method(:hello_world), :Port => 4567
52
73
  We can see this all come together by starting up the application and then visiting +http://localhost:4567/+
53
74
 
54
75
  <shell>
55
- ruby hello_world.rb
76
+ $ ruby hello_world.rb
56
77
  </shell>
57
78
 
58
79
  TODO needs a screenshot? I have one - not sure where to put it.
@@ -64,8 +85,8 @@ Action View can also be used with "Sinatra":http://www.sinatrarb.com/ in the sam
64
85
  Let's start by ensuring that you have the Action Pack and Sinatra gems installed:
65
86
 
66
87
  <shell>
67
- gem install actionpack
68
- gem install sinatra
88
+ $ gem install actionpack
89
+ $ gem install sinatra
69
90
  </shell>
70
91
 
71
92
  Now we'll create the same "Hello World" application in Sinatra.
@@ -85,7 +106,7 @@ end
85
106
  Then, we can run the application:
86
107
 
87
108
  <shell>
88
- ruby hello_world.rb
109
+ $ ruby hello_world.rb
89
110
  </shell>
90
111
 
91
112
  Once the application is running, you can see Sinatra and Action View working together by visiting +http://localhost:4567/+
@@ -94,9 +115,213 @@ TODO needs a screenshot? I have one - not sure where to put it.
94
115
 
95
116
  h3. Templates, Partials and Layouts
96
117
 
97
- TODO...
118
+ As mentioned before, the final HTML output is a composition of three Rails elements: +Templates+, +Partials+ and +Layouts+.
119
+ Find below a brief overview of each one of them.
120
+
121
+ h4. Templates
122
+
123
+ Action View templates can be written in several ways. If the template file has a <tt>.erb</tt> extension then it uses a mixture of ERB (included in Ruby) and HTML. If the template file has a <tt>.builder</tt> extension then a fresh instance of <tt>Builder::XmlMarkup</tt> library is used.
124
+
125
+ Rails supports multiple template systems and uses a file extension to distinguish amongst them. For example, an HTML file using the ERB template system will have <tt>.html.erb</tt> as a file extension.
126
+
127
+ h5. ERB
128
+
129
+ Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
130
+
131
+ Consider the following loop for names:
132
+
133
+ <erb>
134
+ <b>Names of all the people</b>
135
+ <% @people.each do |person| %>
136
+ Name: <%= person.name %><br/>
137
+ <% end %>
138
+ </erb>
139
+
140
+ The loop is setup in regular embedding tags +<% %>+ and the name is written using the output embedding tag +<%= %>+. Note that this is not just a usage suggestion, for Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
141
+
142
+ <erb>
143
+ <%# WRONG %>
144
+ Hi, Mr. <% puts "Frodo" %>
145
+ </erb>
146
+
147
+ To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
148
+
149
+ h5. Builder
150
+
151
+ Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object named +xml+ is automatically made available to templates with a <tt>.builder</tt> extension.
152
+
153
+ Here are some basic examples:
154
+
155
+ <ruby>
156
+ xml.em("emphasized")
157
+ xml.em { xml.b("emph & bold") }
158
+ xml.a("A Link", "href"=>"http://rubyonrails.org")
159
+ xml.target("name"=>"compile", "option"=>"fast")
160
+ </ruby>
161
+
162
+ will produce
163
+
164
+ <html>
165
+ <em>emphasized</em>
166
+ <em><b>emph &amp; bold</b></em>
167
+ <a href="http://rubyonrails.org">A link</a>
168
+ <target option="fast" name="compile" \>
169
+ </html>
170
+
171
+ Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following:
172
+
173
+ <ruby>
174
+ xml.div {
175
+ xml.h1(@person.name)
176
+ xml.p(@person.bio)
177
+ }
178
+ </ruby>
179
+
180
+ would produce something like:
181
+
182
+ <html>
183
+ <div>
184
+ <h1>David Heinemeier Hansson</h1>
185
+ <p>A product of Danish Design during the Winter of '79...</p>
186
+ </div>
187
+ </html>
188
+
189
+ A full-length RSS example actually used on Basecamp:
190
+
191
+ <ruby>
192
+ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
193
+ xml.channel do
194
+ xml.title(@feed_title)
195
+ xml.link(@url)
196
+ xml.description "Basecamp: Recent items"
197
+ xml.language "en-us"
198
+ xml.ttl "40"
199
+
200
+ for item in @recent_items
201
+ xml.item do
202
+ xml.title(item_title(item))
203
+ xml.description(item_description(item)) if item_description(item)
204
+ xml.pubDate(item_pubDate(item))
205
+ xml.guid(@person.firm.account.url + @recent_items.url(item))
206
+ xml.link(@person.firm.account.url + @recent_items.url(item))
207
+ xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
208
+ end
209
+ end
210
+ end
211
+ end
212
+ </ruby>
213
+
214
+ h5. Template caching
215
+
216
+ By default, Rails will compile each template to a method in order to render it. When you alter a template, Rails will check the file's modification time and recompile it in development mode.
217
+
218
+ h4. Partials
219
+
220
+ Partial templates – usually just called "partials" – are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
221
+
222
+ h5. Naming Partials
223
+
224
+ To render a partial as part of a view, you use the +render+ method within the view:
225
+
226
+ <ruby>
227
+ <%= render "menu" %>
228
+ </ruby>
229
+
230
+ This will render a file named +_menu.html.erb+ at that point within the view is being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:
231
+
232
+ <ruby>
233
+ <%= render "shared/menu" %>
234
+ </ruby>
235
+
236
+ That code will pull in the partial from +app/views/shared/_menu.html.erb+.
237
+
238
+ h5. Using Partials to Simplify Views
239
+
240
+ One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this:
241
+
242
+ <erb>
243
+ <%= render "shared/ad_banner" %>
244
+
245
+ <h1>Products</h1>
246
+
247
+ <p>Here are a few of our fine products:</p>
248
+ <% @products.each do |product| %>
249
+ <%= render :partial => "product", :locals => { :product => product } %>
250
+ <% end %>
251
+
252
+ <%= render "shared/footer" %>
253
+ </erb>
254
+
255
+ Here, the +_ad_banner.html.erb+ and +_footer.html.erb+ partials could contain content that is shared among many pages in your application. You don't need to see the details of these sections when you're concentrating on a particular page.
256
+
257
+ h5. The :as and :object options
258
+
259
+ By default <tt>ActionView::Partials::PartialRenderer</tt> has its object in a local variable with the same name as the template. So, given
260
+
261
+ <erb>
262
+ <%= render :partial => "product" %>
263
+ </erb>
264
+
265
+ within product we'll get <tt>@product</tt> in the local variable +product+, as if we had written:
266
+
267
+ <erb>
268
+ <%= render :partial => "product", :locals => { :product => @product } %>
269
+ </erb>
270
+
271
+ With the <tt>:as</tt> option we can specify a different name for said local variable. For example, if we wanted it to be +item+ instead of product+ we'd do:
272
+
273
+ <erb>
274
+ <%= render :partial => "product", :as => 'item' %>
275
+ </erb>
276
+
277
+ The <tt>:object</tt> option can be used to directly specify which object is rendered into the partial; useful when the template's object is elsewhere, in a different ivar or in a local variable for instance.
278
+
279
+ For example, instead of:
280
+
281
+ <erb>
282
+ <%= render :partial => "product", :locals => { :product => @item } %>
283
+ </erb>
98
284
 
99
- TODO see http://guides.rubyonrails.org/layouts_and_rendering.html
285
+ you'd do:
286
+
287
+ <erb>
288
+ <%= render :partial => "product", :object => @item %>
289
+ </erb>
290
+
291
+ The <tt>:object</tt> and <tt>:as</tt> options can be used together.
292
+
293
+ h5. Rendering Collections
294
+
295
+ The example of partial use describes a familiar pattern where a template needs to iterate over an array and render a sub template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial by the same name as the elements contained within.
296
+ So the three-lined example for rendering all the products can be rewritten with a single line:
297
+
298
+ <erb>
299
+ <%= render :partial => "product", :collection => @products %>
300
+ </erb>
301
+
302
+ When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is +_product+ , and within the +_product+ partial, you can refer to +product+ to get the instance that is being rendered.
303
+
304
+ You can use a shorthand syntax for rendering collections. Assuming @products is a collection of +Product+ instances, you can simply write the following to produce the same result:
305
+
306
+ <erb>
307
+ <%= render @products %>
308
+ </erb>
309
+
310
+ Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection.
311
+
312
+ h5. Spacer Templates
313
+
314
+ You can also specify a second partial to be rendered between instances of the main partial by using the +:spacer_template+ option:
315
+
316
+ <erb>
317
+ <%= render @products, :spacer_template => "product_ruler" %>
318
+ </erb>
319
+
320
+ Rails will render the +_product_ruler+ partial (with no data passed in to it) between each pair of +_product+ partials.
321
+
322
+ h4. Layouts
323
+
324
+ TODO...
100
325
 
101
326
  h3. Using Templates, Partials and Layouts in "The Rails Way"
102
327
 
@@ -231,7 +456,7 @@ input("post", "title") # =>
231
456
 
232
457
  h4. AssetTagHelper
233
458
 
234
- This module provides methods for generating HTML that links views to assets such as images, javascripts, stylesheets, and feeds.
459
+ This module provides methods for generating HTML that links views to assets such as images, JavaScript files, stylesheets, and feeds.
235
460
 
236
461
  By default, Rails links to these assets on the current host in the public folder, but you can direct Rails to link to assets from a dedicated assets server by setting +ActionController::Base.asset_host+ in the application configuration, typically in +config/environments/production.rb+. For example, let's say your asset host is +assets.example.com+:
237
462
 
@@ -242,7 +467,7 @@ image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png
242
467
 
243
468
  h5. register_javascript_expansion
244
469
 
245
- Register one or more javascript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register javascript files that the plugin installed in public/javascripts.
470
+ Register one or more JavaScript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register JavaScript files that the plugin installed in +public/javascripts+.
246
471
 
247
472
  <ruby>
248
473
  ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"]
@@ -253,9 +478,6 @@ javascript_include_tag :monkey # =>
253
478
  <script type="text/javascript" src="/javascripts/tail.js"></script>
254
479
  </ruby>
255
480
 
256
- h5. register_javascript_include_default
257
-
258
- Register one or more additional JavaScript files to be included when +javascript_include_tag :defaults+ is called. This method is typically intended to be called from plugin initialization to register additional +.js+ files that the plugin installed in +public/javascripts+.
259
481
 
260
482
  h5. register_stylesheet_expansion
261
483
 
@@ -265,9 +487,9 @@ Register one or more stylesheet files to be included when symbol is passed to +s
265
487
  ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey => ["head", "body", "tail"]
266
488
 
267
489
  stylesheet_link_tag :monkey # =>
268
- <link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" />
269
- <link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" />
270
- <link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" />
490
+ <link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" />
491
+ <link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" />
492
+ <link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" />
271
493
  </ruby>
272
494
 
273
495
  h5. auto_discovery_link_tag
@@ -281,7 +503,7 @@ auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "RSS
281
503
 
282
504
  h5. image_path
283
505
 
284
- Computes the path to an image asset in the public images directory. Full paths from the document root will be passed through. Used internally by +image_tag+ to build the image path.
506
+ Computes the path to an image asset in the +public/images+ directory. Full paths from the document root will be passed through. Used internally by +image_tag+ to build the image path.
285
507
 
286
508
  <ruby>
287
509
  image_path("edit.png") # => /images/edit.png
@@ -289,7 +511,7 @@ image_path("edit.png") # => /images/edit.png
289
511
 
290
512
  h5. image_tag
291
513
 
292
- Returns an html image tag for the source. The source can be a full path or a file that exists in your public images directory.
514
+ Returns an html image tag for the source. The source can be a full path or a file that exists in your +public/images+ directory.
293
515
 
294
516
  <ruby>
295
517
  image_tag("icon.png") # => <img src="/images/icon.png" alt="Icon" />
@@ -297,26 +519,26 @@ image_tag("icon.png") # => <img src="/images/icon.png" alt="Icon" />
297
519
 
298
520
  h5. javascript_include_tag
299
521
 
300
- Returns an html script tag for each of the sources provided. You can pass in the filename (+.js+ extension is optional) of javascript files that exist in your +public/javascripts+ directory for inclusion into the current page or you can pass the full path relative to your document root.
522
+ Returns an html script tag for each of the sources provided. You can pass in the filename (+.js+ extension is optional) of JavaScript files that exist in your +public/javascripts+ directory for inclusion into the current page or you can pass the full path relative to your document root.
301
523
 
302
524
  <ruby>
303
525
  javascript_include_tag "common" # =>
304
526
  <script type="text/javascript" src="/javascripts/common.js"></script>
305
527
  </ruby>
306
528
 
307
- To include the Prototype and Scriptaculous javascript libraries in your application, pass +:defaults+ as the source. When using +:defaults+, if an +application.js+ file exists in your +public/javascripts+ directory, it will be included as well.
529
+ If the application does not use the asset pipeline, to include the jQuery JavaScript library in your application, pass +:defaults+ as the source. When using +:defaults+, if an +application.js+ file exists in your +public/javascripts+ directory, it will be included as well.
308
530
 
309
531
  <ruby>
310
532
  javascript_include_tag :defaults
311
533
  </ruby>
312
534
 
313
- You can also include all javascripts in the javascripts directory using +:all+ as the source.
535
+ You can also include all JavaScript files in the +public/javascripts+ directory using +:all+ as the source.
314
536
 
315
537
  <ruby>
316
538
  javascript_include_tag :all
317
539
  </ruby>
318
540
 
319
- You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be compressed by gzip (leading to faster transfers). Caching will only happen if +ActionController::Base.perform_caching+ is set to true (which is the case by default for the Rails production environment, but not for the development environment).
541
+ You can also cache multiple JavaScript files into one file, which requires less HTTP connections to download and can better be compressed by gzip (leading to faster transfers). Caching will only happen if +ActionController::Base.perform_caching+ is set to true (which is the case by default for the Rails production environment, but not for the development environment).
320
542
 
321
543
  <ruby>
322
544
  javascript_include_tag :all, :cache => true # =>
@@ -325,7 +547,7 @@ javascript_include_tag :all, :cache => true # =>
325
547
 
326
548
  h5. javascript_path
327
549
 
328
- Computes the path to a javascript asset in the +public/javascripts+ directory. If the source filename has no extension, +.js+ will be appended. Full paths from the document root will be passed through. Used internally by +javascript_include_tag+ to build the script path.
550
+ Computes the path to a JavaScript asset in the +public/javascripts+ directory. If the source filename has no extension, +.js+ will be appended. Full paths from the document root will be passed through. Used internally by +javascript_include_tag+ to build the script path.
329
551
 
330
552
  <ruby>
331
553
  javascript_path "common" # => /javascripts/common.js
@@ -355,7 +577,7 @@ stylesheet_link_tag :all, :cache => true
355
577
 
356
578
  h5. stylesheet_path
357
579
 
358
- Computes the path to a stylesheet asset in the public stylesheets directory. If the source filename has no extension, .css will be appended. Full paths from the document root will be passed through. Used internally by stylesheet_link_tag to build the stylesheet path.
580
+ Computes the path to a stylesheet asset in the +public/stylesheets+ directory. If the source filename has no extension, .css will be appended. Full paths from the document root will be passed through. Used internally by stylesheet_link_tag to build the stylesheet path.
359
581
 
360
582
  <ruby>
361
583
  stylesheet_path "application" # => /stylesheets/application.css
@@ -370,14 +592,14 @@ This helper makes building an ATOM feed easy. Here's a full usage example:
370
592
  *config/routes.rb*
371
593
 
372
594
  <ruby>
373
- map.resources :posts
595
+ resources :posts
374
596
  </ruby>
375
597
 
376
598
  *app/controllers/posts_controller.rb*
377
599
 
378
600
  <ruby>
379
601
  def index
380
- @posts = Post.find(:all)
602
+ @posts = Post.all
381
603
 
382
604
  respond_to do |format|
383
605
  format.html
@@ -428,7 +650,7 @@ A method for caching fragments of a view rather than an entire action or page. T
428
650
 
429
651
  <ruby>
430
652
  <% cache do %>
431
- <%= render :partial => "shared/footer" %>
653
+ <%= render "shared/footer" %>
432
654
  <% end %>
433
655
  </ruby>
434
656
 
@@ -442,7 +664,7 @@ The +capture+ method allows you to extract part of a template into a variable. Y
442
664
  <% @greeting = capture do %>
443
665
  <p>Welcome! The date and time is <%= Time.now %></p>
444
666
  <% end %>
445
- <ruby>
667
+ </ruby>
446
668
 
447
669
  The captured variable can then be used anywhere else.
448
670
 
@@ -654,7 +876,7 @@ The core method of this helper, form_for, gives you the ability to create a form
654
876
 
655
877
  <ruby>
656
878
  # Note: a @person variable will have been created in the controller (e.g. @person = Person.new)
657
- <%= form_for :person, @person, :url => { :action => "create" } do |f| %>
879
+ <%= form_for @person, :url => { :action => "create" } do |f| %>
658
880
  <%= f.text_field :first_name %>
659
881
  <%= f.text_field :last_name %>
660
882
  <%= submit_tag 'Create' %>
@@ -812,7 +1034,7 @@ end
812
1034
  Sample usage (selecting the associated Author for an instance of Post, +@post+):
813
1035
 
814
1036
  <ruby>
815
- collection_select(:post, :author_id, Author.find(:all), :id, :name_with_initial, {:prompt => true})
1037
+ collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => true})
816
1038
  </ruby>
817
1039
 
818
1040
  If @post.author_id is already 1, this would return:
@@ -891,7 +1113,7 @@ Note: Only the +option+ tags are returned, you have to wrap this call in a regul
891
1113
 
892
1114
  h5. options_from_collection_for_select
893
1115
 
894
- Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
1116
+ Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
895
1117
 
896
1118
  <ruby>
897
1119
  # options_from_collection_for_select(collection, value_method, text_method, selected = nil)
@@ -913,7 +1135,7 @@ Create a select tag and a series of contained option tags for the provided objec
913
1135
  Example with @post.person_id => 1:
914
1136
 
915
1137
  <ruby>
916
- select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, { :include_blank => true })
1138
+ select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })
917
1139
  </ruby>
918
1140
 
919
1141
  could become:
@@ -1079,8 +1301,6 @@ h4. JavaScriptHelper
1079
1301
 
1080
1302
  Provides functionality for working with JavaScript in your views.
1081
1303
 
1082
- 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.
1083
-
1084
1304
  h5. button_to_function
1085
1305
 
1086
1306
  Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
@@ -1180,16 +1400,6 @@ number_with_precision(111.2345) # => 111.235
1180
1400
  number_with_precision(111.2345, 2) # => 111.23
1181
1401
  </ruby>
1182
1402
 
1183
- h4. PrototypeHelper
1184
-
1185
- Prototype is a JavaScript library that provides DOM manipulation, Ajax functionality, and more traditional object-oriented facilities for JavaScript. This module provides a set of helpers to make it more convenient to call functions from Prototype using Rails, including functionality to call remote Rails methods (that is, making a background request to a Rails action) using Ajax.
1186
-
1187
- To be able to use these helpers, you must first include the Prototype JavaScript framework in the HEAD of the pages with Prototype functions.
1188
-
1189
- <ruby>
1190
- javascript_include_tag 'prototype'
1191
- </ruby>
1192
-
1193
1403
  h5. evaluate_remote_response
1194
1404
 
1195
1405
  Returns +eval(request.responseText)+ which is the JavaScript function that form_remote_tag can call in +:complete+ to evaluate a multiple update return document using +update_element_function+ calls.
@@ -1286,171 +1496,6 @@ would generate:
1286
1496
  return false;" type="button" value="Create" />
1287
1497
  </html>
1288
1498
 
1289
- h5. update_page
1290
-
1291
- Yields a JavaScriptGenerator and returns the generated JavaScript code. Use this to update multiple elements on a page in an Ajax response.
1292
-
1293
- <ruby>
1294
- update_page do |page|
1295
- page.hide 'spinner'
1296
- end
1297
- </ruby>
1298
-
1299
- h5. update_page_tag
1300
-
1301
- Works like update_page but wraps the generated JavaScript in a +script+ tag. Use this to include generated JavaScript in an ERb template.
1302
-
1303
- h4. PrototypeHelper::JavaScriptGenerator::GeneratorMethods
1304
-
1305
- JavaScriptGenerator generates blocks of JavaScript code that allow you to change the content and presentation of multiple DOM elements. Use this in your Ajax response bodies, either in a +script+ tag or as plain JavaScript sent with a Content-type of "text/javascript".
1306
-
1307
- h5(#push). <<
1308
-
1309
- Writes raw JavaScript to the page.
1310
-
1311
- <ruby>
1312
- page << "alert('JavaScript with Prototype.');"
1313
- </ruby>
1314
-
1315
- h5(#at). []
1316
-
1317
- Returns a element reference by finding it through it's id in the DOM.
1318
-
1319
- <ruby>
1320
- page['blank_slate'].show # => $('blank_slate').show();
1321
- </ruby>
1322
-
1323
- h5. alert
1324
-
1325
- Displays an alert dialog with the given message.
1326
-
1327
- <ruby>
1328
- page.alert('This message is from Rails!')
1329
- </ruby>
1330
-
1331
- h5. assign
1332
-
1333
- Assigns the JavaScript variable the given value.
1334
-
1335
- <ruby>
1336
- page.assign 'tabulated_total', @total_from_cart
1337
- </ruby>
1338
-
1339
- h5. call
1340
-
1341
- Calls the JavaScript function, optionally with the given arguments.
1342
-
1343
- <ruby>
1344
- page.call 'Element.replace', 'my_element', "My content to replace with."
1345
- </ruby>
1346
-
1347
- h5. delay
1348
-
1349
- Executes the content of the block after a delay of the number of seconds provided.
1350
-
1351
- <ruby>
1352
- page.delay(20) do
1353
- page.visual_effect :fade, 'notice'
1354
- end
1355
- </ruby>
1356
-
1357
- h5. draggable
1358
-
1359
- Creates a script.aculo.us draggable element. See ActionView::Helpers::ScriptaculousHelper for more information.
1360
-
1361
- h5. drop_receiving
1362
-
1363
- Creates a script.aculo.us drop receiving element. See ActionView::Helpers::ScriptaculousHelper for more information.
1364
-
1365
- h5. hide
1366
-
1367
- Hides the visible DOM elements with the given ids.
1368
-
1369
- <ruby>
1370
- page.hide 'person_29', 'person_9', 'person_0'
1371
- </ruby>
1372
-
1373
- h5. insert_html
1374
-
1375
- Inserts HTML at the specified position relative to the DOM element identified by the given id.
1376
-
1377
- <ruby>
1378
- page.insert_html :bottom, 'my_list', '<li>Last item</li>'
1379
- </ruby>
1380
-
1381
- h5. literal
1382
-
1383
- Returns an object whose to_json evaluates to the code provided. Use this to pass a literal JavaScript expression as an argument to another JavaScriptGenerator method.
1384
-
1385
- h5. redirect_to
1386
-
1387
- Redirects the browser to the given location using JavaScript, in the same form as +url_for+.
1388
-
1389
- <ruby>
1390
- page.redirect_to(:controller => 'accounts', :action => 'new')
1391
- </ruby>
1392
-
1393
- h5. remove
1394
-
1395
- Removes the DOM elements with the given ids from the page.
1396
-
1397
- <ruby>
1398
- page.remove 'person_23', 'person_9', 'person_2'
1399
- </ruby>
1400
-
1401
- h5. replace
1402
-
1403
- Replaces the "outer HTML" (i.e., the entire element, not just its contents) of the DOM element with the given id.
1404
-
1405
- <ruby>
1406
- page.replace 'person-45', :partial => 'person', :object => @person
1407
- </ruby>
1408
-
1409
- h5. replace_html
1410
-
1411
- Replaces the inner HTML of the DOM element with the given id.
1412
-
1413
- <ruby>
1414
- page.replace_html 'person-45', :partial => 'person', :object => @person
1415
- </ruby>
1416
-
1417
- h5(#prototype-select). select
1418
-
1419
- Returns a collection reference by finding it through a CSS pattern in the DOM.
1420
-
1421
- <ruby>
1422
- page.select('p.welcome b').first.hide # => $$('p.welcome b').first().hide();
1423
- </ruby>
1424
-
1425
- h5. show
1426
-
1427
- Shows hidden DOM elements with the given ids.
1428
-
1429
- <ruby>
1430
- page.show 'person_6', 'person_13', 'person_223'
1431
- </ruby>
1432
-
1433
- h5. sortable
1434
-
1435
- Creates a script.aculo.us sortable element. Useful to recreate sortable elements after items get added or deleted. See ActionView::Helpers::ScriptaculousHelper for more information.
1436
-
1437
- h5. toggle
1438
-
1439
- Toggles the visibility of the DOM elements with the given ids. Example:
1440
-
1441
- <ruby>
1442
- page.toggle 'person_14', 'person_12', 'person_23' # Hides the elements
1443
- page.toggle 'person_14', 'person_12', 'person_23' # Shows the previously hidden elements
1444
- </ruby>
1445
-
1446
- h5. visual_effect
1447
-
1448
- Starts a script.aculo.us visual effect. See ActionView::Helpers::ScriptaculousHelper for more information.
1449
-
1450
-
1451
- TODO start from RecordIdentificationHelper
1452
-
1453
-
1454
1499
  h3. Localized Views
1455
1500
 
1456
1501
  Action View has the ability render different templates depending on the current locale.
@@ -1475,5 +1520,6 @@ You can read more about the Rails Internationalization (I18n) API "here":i18n.ht
1475
1520
 
1476
1521
  h3. Changelog
1477
1522
 
1478
- * September 3, 2009: Continuing work by Trevor Turk, leveraging the "Action Pack docs":http://ap.rubyonrails.org/ and "What's new in Edge Rails":http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts
1523
+ * April 16, 2011: Added 'Using Action View with Rails', 'Templates' and 'Partials' sections. "Sebastian Martinez":http://wyeworks.com
1524
+ * September 3, 2009: Continuing work by Trevor Turk, leveraging the Action Pack docs and "What's new in Edge Rails":http://ryandaigle.com/articles/2007/8/3/what-s-new-in-edge-rails-partials-get-layouts
1479
1525
  * April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs