railties 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (334) hide show
  1. data/CHANGELOG +2201 -0
  2. data/README +286 -0
  3. data/bin/rails +11 -0
  4. data/builtin/rails_info/rails/info.rb +147 -0
  5. data/builtin/rails_info/rails/info_controller.rb +15 -0
  6. data/builtin/rails_info/rails/info_helper.rb +2 -0
  7. data/builtin/routes.rb +3 -0
  8. data/guides/files/javascripts/code_highlighter.js +188 -0
  9. data/guides/files/javascripts/guides.js +7 -0
  10. data/guides/files/javascripts/highlighters.js +90 -0
  11. data/guides/files/stylesheets/main.css +441 -0
  12. data/guides/files/stylesheets/print.css +52 -0
  13. data/guides/files/stylesheets/reset.css +43 -0
  14. data/guides/files/stylesheets/style.css +13 -0
  15. data/guides/files/stylesheets/syntax.css +31 -0
  16. data/guides/images/belongs_to.png +0 -0
  17. data/guides/images/book_icon.gif +0 -0
  18. data/guides/images/bullet.gif +0 -0
  19. data/guides/images/chapters_icon.gif +0 -0
  20. data/guides/images/check_bullet.gif +0 -0
  21. data/guides/images/credits_pic_blank.gif +0 -0
  22. data/guides/images/csrf.png +0 -0
  23. data/guides/images/customized_error_messages.png +0 -0
  24. data/guides/images/error_messages.png +0 -0
  25. data/guides/images/feature_tile.gif +0 -0
  26. data/guides/images/footer_tile.gif +0 -0
  27. data/guides/images/fxn.png +0 -0
  28. data/guides/images/grey_bullet.gif +0 -0
  29. data/guides/images/habtm.png +0 -0
  30. data/guides/images/has_many.png +0 -0
  31. data/guides/images/has_many_through.png +0 -0
  32. data/guides/images/has_one.png +0 -0
  33. data/guides/images/has_one_through.png +0 -0
  34. data/guides/images/header_backdrop.png +0 -0
  35. data/guides/images/header_tile.gif +0 -0
  36. data/guides/images/i18n/demo_localized_pirate.png +0 -0
  37. data/guides/images/i18n/demo_translated_en.png +0 -0
  38. data/guides/images/i18n/demo_translated_pirate.png +0 -0
  39. data/guides/images/i18n/demo_translation_missing.png +0 -0
  40. data/guides/images/i18n/demo_untranslated.png +0 -0
  41. data/guides/images/icons/README +5 -0
  42. data/guides/images/icons/callouts/1.png +0 -0
  43. data/guides/images/icons/callouts/10.png +0 -0
  44. data/guides/images/icons/callouts/11.png +0 -0
  45. data/guides/images/icons/callouts/12.png +0 -0
  46. data/guides/images/icons/callouts/13.png +0 -0
  47. data/guides/images/icons/callouts/14.png +0 -0
  48. data/guides/images/icons/callouts/15.png +0 -0
  49. data/guides/images/icons/callouts/2.png +0 -0
  50. data/guides/images/icons/callouts/3.png +0 -0
  51. data/guides/images/icons/callouts/4.png +0 -0
  52. data/guides/images/icons/callouts/5.png +0 -0
  53. data/guides/images/icons/callouts/6.png +0 -0
  54. data/guides/images/icons/callouts/7.png +0 -0
  55. data/guides/images/icons/callouts/8.png +0 -0
  56. data/guides/images/icons/callouts/9.png +0 -0
  57. data/guides/images/icons/caution.png +0 -0
  58. data/guides/images/icons/example.png +0 -0
  59. data/guides/images/icons/home.png +0 -0
  60. data/guides/images/icons/important.png +0 -0
  61. data/guides/images/icons/next.png +0 -0
  62. data/guides/images/icons/note.png +0 -0
  63. data/guides/images/icons/prev.png +0 -0
  64. data/guides/images/icons/tip.png +0 -0
  65. data/guides/images/icons/up.png +0 -0
  66. data/guides/images/icons/warning.png +0 -0
  67. data/guides/images/nav_arrow.gif +0 -0
  68. data/guides/images/polymorphic.png +0 -0
  69. data/guides/images/posts_index.png +0 -0
  70. data/guides/images/rails_guides_logo.gif +0 -0
  71. data/guides/images/rails_logo_remix.gif +0 -0
  72. data/guides/images/rails_welcome.png +0 -0
  73. data/guides/images/session_fixation.png +0 -0
  74. data/guides/images/tab_grey.gif +0 -0
  75. data/guides/images/tab_info.gif +0 -0
  76. data/guides/images/tab_note.gif +0 -0
  77. data/guides/images/tab_red.gif +0 -0
  78. data/guides/images/tab_yellow.gif +0 -0
  79. data/guides/images/tab_yellow.png +0 -0
  80. data/guides/images/validation_error_messages.png +0 -0
  81. data/guides/rails_guides.rb +44 -0
  82. data/guides/rails_guides/generator.rb +178 -0
  83. data/guides/rails_guides/helpers.rb +34 -0
  84. data/guides/rails_guides/indexer.rb +55 -0
  85. data/guides/rails_guides/levenshtein.rb +31 -0
  86. data/guides/rails_guides/textile_extensions.rb +41 -0
  87. data/guides/source/2_2_release_notes.textile +422 -0
  88. data/guides/source/2_3_release_notes.textile +610 -0
  89. data/guides/source/3_0_release_notes.textile +560 -0
  90. data/guides/source/action_controller_overview.textile +783 -0
  91. data/guides/source/action_mailer_basics.textile +437 -0
  92. data/guides/source/action_view_overview.textile +1481 -0
  93. data/guides/source/active_record_basics.textile +204 -0
  94. data/guides/source/active_record_querying.textile +961 -0
  95. data/guides/source/active_support_core_extensions.textile +1835 -0
  96. data/guides/source/activerecord_validations_callbacks.textile +1127 -0
  97. data/guides/source/ajax_on_rails.textile +342 -0
  98. data/guides/source/association_basics.textile +1816 -0
  99. data/guides/source/caching_with_rails.textile +390 -0
  100. data/guides/source/command_line.textile +589 -0
  101. data/guides/source/configuring.textile +290 -0
  102. data/guides/source/contribute.textile +71 -0
  103. data/guides/source/contributing_to_rails.textile +272 -0
  104. data/guides/source/credits.textile.erb +52 -0
  105. data/guides/source/debugging_rails_applications.textile +709 -0
  106. data/guides/source/form_helpers.textile +768 -0
  107. data/guides/source/generators.textile +378 -0
  108. data/guides/source/getting_started.textile +1310 -0
  109. data/guides/source/i18n.textile +879 -0
  110. data/guides/source/index.textile.erb +124 -0
  111. data/guides/source/layout.html.erb +103 -0
  112. data/guides/source/layouts_and_rendering.textile +979 -0
  113. data/guides/source/migrations.textile +591 -0
  114. data/guides/source/nested_model_forms.textile +222 -0
  115. data/guides/source/performance_testing.textile +531 -0
  116. data/guides/source/plugins.textile +1512 -0
  117. data/guides/source/rails_application_templates.textile +238 -0
  118. data/guides/source/rails_on_rack.textile +306 -0
  119. data/guides/source/routing.textile +903 -0
  120. data/guides/source/security.textile +984 -0
  121. data/guides/source/testing.textile +946 -0
  122. data/lib/generators/erb.rb +8 -0
  123. data/lib/generators/erb/controller/controller_generator.rb +21 -0
  124. data/lib/generators/erb/controller/templates/view.html.erb +2 -0
  125. data/lib/generators/erb/mailer/mailer_generator.rb +20 -0
  126. data/lib/generators/erb/mailer/templates/view.text.erb +3 -0
  127. data/lib/generators/erb/scaffold/scaffold_generator.rb +53 -0
  128. data/lib/generators/erb/scaffold/templates/_form.html.erb +13 -0
  129. data/lib/generators/erb/scaffold/templates/edit.html.erb +6 -0
  130. data/lib/generators/erb/scaffold/templates/index.html.erb +27 -0
  131. data/lib/generators/erb/scaffold/templates/layout.html.erb +16 -0
  132. data/lib/generators/erb/scaffold/templates/new.html.erb +5 -0
  133. data/lib/generators/erb/scaffold/templates/show.html.erb +10 -0
  134. data/lib/generators/rails/app/USAGE +9 -0
  135. data/lib/generators/rails/app/app_generator.rb +262 -0
  136. data/lib/generators/rails/app/templates/Gemfile +34 -0
  137. data/lib/generators/rails/app/templates/README +243 -0
  138. data/lib/generators/rails/app/templates/Rakefile +10 -0
  139. data/lib/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
  140. data/lib/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
  141. data/lib/generators/rails/app/templates/app/models/.empty_directory +0 -0
  142. data/lib/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
  143. data/lib/generators/rails/app/templates/config.ru +4 -0
  144. data/lib/generators/rails/app/templates/config/application.rb +51 -0
  145. data/lib/generators/rails/app/templates/config/boot.rb +17 -0
  146. data/lib/generators/rails/app/templates/config/databases/frontbase.yml +28 -0
  147. data/lib/generators/rails/app/templates/config/databases/ibm_db.yml +71 -0
  148. data/lib/generators/rails/app/templates/config/databases/mysql.yml +60 -0
  149. data/lib/generators/rails/app/templates/config/databases/oracle.yml +39 -0
  150. data/lib/generators/rails/app/templates/config/databases/postgresql.yml +51 -0
  151. data/lib/generators/rails/app/templates/config/databases/sqlite3.yml +22 -0
  152. data/lib/generators/rails/app/templates/config/environment.rb +5 -0
  153. data/lib/generators/rails/app/templates/config/environments/development.rb.tt +19 -0
  154. data/lib/generators/rails/app/templates/config/environments/production.rb.tt +33 -0
  155. data/lib/generators/rails/app/templates/config/environments/test.rb.tt +29 -0
  156. data/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  157. data/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +7 -0
  158. data/lib/generators/rails/app/templates/config/initializers/inflections.rb +10 -0
  159. data/lib/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
  160. data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +15 -0
  161. data/lib/generators/rails/app/templates/config/locales/en.yml +5 -0
  162. data/lib/generators/rails/app/templates/config/routes.rb +58 -0
  163. data/lib/generators/rails/app/templates/db/seeds.rb +7 -0
  164. data/lib/generators/rails/app/templates/doc/README_FOR_APP +2 -0
  165. data/lib/generators/rails/app/templates/gitignore +4 -0
  166. data/lib/generators/rails/app/templates/public/404.html +26 -0
  167. data/lib/generators/rails/app/templates/public/422.html +26 -0
  168. data/lib/generators/rails/app/templates/public/500.html +26 -0
  169. data/lib/generators/rails/app/templates/public/favicon.ico +0 -0
  170. data/lib/generators/rails/app/templates/public/images/rails.png +0 -0
  171. data/lib/generators/rails/app/templates/public/index.html +278 -0
  172. data/lib/generators/rails/app/templates/public/javascripts/application.js +2 -0
  173. data/lib/generators/rails/app/templates/public/javascripts/controls.js +963 -0
  174. data/lib/generators/rails/app/templates/public/javascripts/dragdrop.js +973 -0
  175. data/lib/generators/rails/app/templates/public/javascripts/effects.js +1128 -0
  176. data/lib/generators/rails/app/templates/public/javascripts/prototype.js +4320 -0
  177. data/lib/generators/rails/app/templates/public/javascripts/rails.js +110 -0
  178. data/lib/generators/rails/app/templates/public/robots.txt +5 -0
  179. data/lib/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  180. data/lib/generators/rails/app/templates/script/rails +9 -0
  181. data/lib/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  182. data/lib/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  183. data/lib/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  184. data/lib/generators/rails/app/templates/test/performance/browsing_test.rb +9 -0
  185. data/lib/generators/rails/app/templates/test/test_helper.rb +13 -0
  186. data/lib/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  187. data/lib/generators/rails/controller/USAGE +18 -0
  188. data/lib/generators/rails/controller/controller_generator.rb +14 -0
  189. data/lib/generators/rails/controller/templates/controller.rb +7 -0
  190. data/lib/generators/rails/generator/USAGE +11 -0
  191. data/lib/generators/rails/generator/generator_generator.rb +25 -0
  192. data/lib/generators/rails/generator/templates/%file_name%_generator.rb.tt +5 -0
  193. data/lib/generators/rails/generator/templates/USAGE.tt +8 -0
  194. data/lib/generators/rails/generator/templates/templates/.empty_directory +0 -0
  195. data/lib/generators/rails/helper/USAGE +17 -0
  196. data/lib/generators/rails/helper/helper_generator.rb +13 -0
  197. data/lib/generators/rails/helper/templates/helper.rb +2 -0
  198. data/lib/generators/rails/integration_test/USAGE +10 -0
  199. data/lib/generators/rails/integration_test/integration_test_generator.rb +7 -0
  200. data/lib/generators/rails/mailer/USAGE +15 -0
  201. data/lib/generators/rails/mailer/mailer_generator.rb +14 -0
  202. data/lib/generators/rails/mailer/templates/mailer.rb +16 -0
  203. data/lib/generators/rails/metal/USAGE +8 -0
  204. data/lib/generators/rails/metal/metal_generator.rb +11 -0
  205. data/lib/generators/rails/metal/templates/metal.rb +12 -0
  206. data/lib/generators/rails/migration/USAGE +29 -0
  207. data/lib/generators/rails/migration/migration_generator.rb +8 -0
  208. data/lib/generators/rails/model/USAGE +30 -0
  209. data/lib/generators/rails/model/model_generator.rb +8 -0
  210. data/lib/generators/rails/model_subclass/model_subclass_generator.rb +12 -0
  211. data/lib/generators/rails/observer/USAGE +12 -0
  212. data/lib/generators/rails/observer/observer_generator.rb +7 -0
  213. data/lib/generators/rails/performance_test/USAGE +10 -0
  214. data/lib/generators/rails/performance_test/performance_test_generator.rb +7 -0
  215. data/lib/generators/rails/plugin/USAGE +13 -0
  216. data/lib/generators/rails/plugin/plugin_generator.rb +47 -0
  217. data/lib/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
  218. data/lib/generators/rails/plugin/templates/README.tt +13 -0
  219. data/lib/generators/rails/plugin/templates/Rakefile.tt +10 -0
  220. data/lib/generators/rails/plugin/templates/init.rb +1 -0
  221. data/lib/generators/rails/plugin/templates/install.rb +1 -0
  222. data/lib/generators/rails/plugin/templates/lib/%file_name%.rb.tt +1 -0
  223. data/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +4 -0
  224. data/lib/generators/rails/plugin/templates/uninstall.rb +1 -0
  225. data/lib/generators/rails/resource/USAGE +23 -0
  226. data/lib/generators/rails/resource/resource_generator.rb +34 -0
  227. data/lib/generators/rails/scaffold/USAGE +29 -0
  228. data/lib/generators/rails/scaffold/scaffold_generator.rb +13 -0
  229. data/lib/generators/rails/scaffold_controller/USAGE +20 -0
  230. data/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +27 -0
  231. data/lib/generators/rails/scaffold_controller/templates/controller.rb +85 -0
  232. data/lib/generators/rails/session_migration/USAGE +8 -0
  233. data/lib/generators/rails/session_migration/session_migration_generator.rb +8 -0
  234. data/lib/generators/rails/stylesheets/USAGE +5 -0
  235. data/lib/generators/rails/stylesheets/stylesheets_generator.rb +9 -0
  236. data/lib/generators/rails/stylesheets/templates/scaffold.css +61 -0
  237. data/lib/generators/test_unit.rb +8 -0
  238. data/lib/generators/test_unit/controller/controller_generator.rb +14 -0
  239. data/lib/generators/test_unit/controller/templates/functional_test.rb +8 -0
  240. data/lib/generators/test_unit/helper/helper_generator.rb +13 -0
  241. data/lib/generators/test_unit/helper/templates/helper_test.rb +4 -0
  242. data/lib/generators/test_unit/integration/integration_generator.rb +13 -0
  243. data/lib/generators/test_unit/integration/templates/integration_test.rb +10 -0
  244. data/lib/generators/test_unit/mailer/mailer_generator.rb +21 -0
  245. data/lib/generators/test_unit/mailer/templates/fixture +3 -0
  246. data/lib/generators/test_unit/mailer/templates/functional_test.rb +22 -0
  247. data/lib/generators/test_unit/model/model_generator.rb +24 -0
  248. data/lib/generators/test_unit/model/templates/fixtures.yml +23 -0
  249. data/lib/generators/test_unit/model/templates/unit_test.rb +8 -0
  250. data/lib/generators/test_unit/observer/observer_generator.rb +13 -0
  251. data/lib/generators/test_unit/observer/templates/unit_test.rb +8 -0
  252. data/lib/generators/test_unit/performance/performance_generator.rb +13 -0
  253. data/lib/generators/test_unit/performance/templates/performance_test.rb +9 -0
  254. data/lib/generators/test_unit/plugin/plugin_generator.rb +13 -0
  255. data/lib/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +8 -0
  256. data/lib/generators/test_unit/plugin/templates/test_helper.rb +3 -0
  257. data/lib/generators/test_unit/scaffold/scaffold_generator.rb +18 -0
  258. data/lib/generators/test_unit/scaffold/templates/functional_test.rb +47 -0
  259. data/lib/rails.rb +95 -0
  260. data/lib/rails/all.rb +14 -0
  261. data/lib/rails/application.rb +125 -0
  262. data/lib/rails/application/bootstrap.rb +85 -0
  263. data/lib/rails/application/configurable.rb +19 -0
  264. data/lib/rails/application/configuration.rb +86 -0
  265. data/lib/rails/application/finisher.rb +49 -0
  266. data/lib/rails/application/metal_loader.rb +50 -0
  267. data/lib/rails/application/railties.rb +31 -0
  268. data/lib/rails/application/routes_reloader.rb +46 -0
  269. data/lib/rails/backtrace_cleaner.rb +54 -0
  270. data/lib/rails/code_statistics.rb +107 -0
  271. data/lib/rails/commands.rb +72 -0
  272. data/lib/rails/commands/application.rb +13 -0
  273. data/lib/rails/commands/console.rb +55 -0
  274. data/lib/rails/commands/dbconsole.rb +104 -0
  275. data/lib/rails/commands/destroy.rb +9 -0
  276. data/lib/rails/commands/generate.rb +9 -0
  277. data/lib/rails/commands/performance/benchmarker.rb +23 -0
  278. data/lib/rails/commands/performance/profiler.rb +46 -0
  279. data/lib/rails/commands/plugin.rb +542 -0
  280. data/lib/rails/commands/runner.rb +51 -0
  281. data/lib/rails/commands/server.rb +75 -0
  282. data/lib/rails/commands/update.rb +9 -0
  283. data/lib/rails/configuration.rb +191 -0
  284. data/lib/rails/console/app.rb +33 -0
  285. data/lib/rails/console/helpers.rb +5 -0
  286. data/lib/rails/console/sandbox.rb +6 -0
  287. data/lib/rails/deprecation.rb +62 -0
  288. data/lib/rails/dispatcher.rb +24 -0
  289. data/lib/rails/engine.rb +130 -0
  290. data/lib/rails/engine/configurable.rb +25 -0
  291. data/lib/rails/engine/configuration.rb +49 -0
  292. data/lib/rails/generators.rb +289 -0
  293. data/lib/rails/generators/actions.rb +309 -0
  294. data/lib/rails/generators/active_model.rb +78 -0
  295. data/lib/rails/generators/base.rb +362 -0
  296. data/lib/rails/generators/generated_attribute.rb +48 -0
  297. data/lib/rails/generators/migration.rb +64 -0
  298. data/lib/rails/generators/named_base.rb +95 -0
  299. data/lib/rails/generators/resource_helpers.rb +80 -0
  300. data/lib/rails/generators/test_case.rb +239 -0
  301. data/lib/rails/initializable.rb +97 -0
  302. data/lib/rails/paths.rb +144 -0
  303. data/lib/rails/performance_test_help.rb +3 -0
  304. data/lib/rails/plugin.rb +64 -0
  305. data/lib/rails/rack.rb +8 -0
  306. data/lib/rails/rack/debugger.rb +23 -0
  307. data/lib/rails/rack/log_tailer.rb +33 -0
  308. data/lib/rails/rack/logger.rb +34 -0
  309. data/lib/rails/rack/static.rb +5 -0
  310. data/lib/rails/railtie.rb +74 -0
  311. data/lib/rails/railtie/configurable.rb +23 -0
  312. data/lib/rails/railtie/configuration.rb +9 -0
  313. data/lib/rails/railties_path.rb +1 -0
  314. data/lib/rails/ruby_version_check.rb +10 -0
  315. data/lib/rails/rubyprof_ext.rb +35 -0
  316. data/lib/rails/source_annotation_extractor.rb +102 -0
  317. data/lib/rails/subscriber.rb +108 -0
  318. data/lib/rails/subscriber/test_helper.rb +98 -0
  319. data/lib/rails/tasks.rb +16 -0
  320. data/lib/rails/tasks/annotations.rake +20 -0
  321. data/lib/rails/tasks/documentation.rake +96 -0
  322. data/lib/rails/tasks/framework.rake +69 -0
  323. data/lib/rails/tasks/log.rake +9 -0
  324. data/lib/rails/tasks/middleware.rake +7 -0
  325. data/lib/rails/tasks/misc.rake +71 -0
  326. data/lib/rails/tasks/routes.rake +17 -0
  327. data/lib/rails/tasks/statistics.rake +16 -0
  328. data/lib/rails/tasks/tmp.rake +37 -0
  329. data/lib/rails/test_help.rb +30 -0
  330. data/lib/rails/test_unit/railtie.rb +17 -0
  331. data/lib/rails/test_unit/testing.rake +130 -0
  332. data/lib/rails/version.rb +9 -0
  333. data/lib/rails/webrick_server.rb +156 -0
  334. metadata +427 -0
@@ -0,0 +1,437 @@
1
+ h2. Action Mailer Basics
2
+
3
+ This guide should provide you with all you need to get started in sending and receiving emails from and to your application, and many internals of Action Mailer. It also covers how to test your mailers.
4
+
5
+ endprologue.
6
+
7
+ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not work in other versions of Rails.
8
+
9
+ h3. Introduction
10
+
11
+ Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+.
12
+
13
+ h3. Sending Emails
14
+
15
+ This section will provide a step-by-step guide to creating a mailer and its views.
16
+
17
+ h4. Walkthrough to Generating a Mailer
18
+
19
+ h5. Create the Mailer
20
+
21
+ <shell>
22
+ ./script/generate mailer UserMailer
23
+ create app/mailers/user_mailer.rb
24
+ invoke erb
25
+ create app/views/user_mailer
26
+ invoke test_unit
27
+ create test/functional/user_mailer_test.rb
28
+ </shell>
29
+
30
+ So we got the mailer, the fixtures, and the tests.
31
+
32
+ h5. Edit the Mailer
33
+
34
+ +app/mailers/user_mailer.rb+ contains an empty mailer:
35
+
36
+ <ruby>
37
+ class UserMailer < ActionMailer::Base
38
+ default :from => "from@example.com"
39
+ end
40
+ </ruby>
41
+
42
+ Let's add a method called +welcome_email+, that will send an email to the user's registered email address:
43
+
44
+ <ruby>
45
+ class UserMailer < ActionMailer::Base
46
+ default :from => "notifications@example.com"
47
+
48
+ def welcome_email(user)
49
+ @user = user
50
+ @url = "http://example.com/login"
51
+ mail(:to => user.email,
52
+ :subject => "Welcome to My Awesome Site")
53
+ end
54
+
55
+ end
56
+ </ruby>
57
+
58
+ Here is a quick explanation of the items presented in the preceding method. For a full list of all available options, please have a look further down at the Complete List of ActionMailer user-settable attributes section.
59
+
60
+ * <tt>default Hash</tt> - This is a hash of default values for any email you send, in this case we are setting the <tt>:from</tt> header to a value for all messages in this class, this can be overridden on a per email basis
61
+ * +mail+ - The actual email message, we are passing the <tt>:to</tt> and <tt>:subject</tt> headers in|
62
+
63
+ And instance variables we define in the method become available for use in the view.
64
+
65
+ h5. Create a Mailer View
66
+
67
+ Create a file called +welcome_email.html.erb+ in +app/views/user_mailer/+. This will be the template used for the email, formatted in HTML:
68
+
69
+ <erb>
70
+ <!DOCTYPE html>
71
+ <html>
72
+ <head>
73
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
74
+ </head>
75
+ <body>
76
+ <h1>Welcome to example.com, <%= @user.name %></h1>
77
+ <p>
78
+ You have successfully signed up to example.com,
79
+ your username is: <%= @user.login %>.<br/>
80
+ </p>
81
+ <p>
82
+ To login to the site, just follow this link: <%= @url %>.
83
+ </p>
84
+ <p>Thanks for joining and have a great day!</p>
85
+ </body>
86
+ </html>
87
+ </erb>
88
+
89
+ It is also a good idea to make a text part for this email, to do this, create a file called +welcome_email.text.erb+ in +app/views/user_mailer/+:
90
+
91
+ <erb>
92
+ Welcome to example.com, <%= @user.name %>
93
+ ===============================================
94
+
95
+ You have successfully signed up to example.com,
96
+ your username is: <%= @user.login %>.
97
+
98
+ To login to the site, just follow this link: <%= @url %>.
99
+
100
+ Thanks for joining and have a great day!
101
+ </erb>
102
+
103
+ When you call the +mail+ method now, Action Mailer will detect the two templates (text and HTML) and automatically generate a <tt>multipart/alternative</tt> email.
104
+
105
+ h5. Wire It Up So That the System Sends the Email When a User Signs Up
106
+
107
+ There are three ways to achieve this. One is to send the email from the controller that sends the email, another is to put it in a +before_create+ callback in the user model, and the last one is to use an observer on the user model. Whether you use the second or third methods is up to you, but staying away from the first is recommended. Not because it's wrong, but because it keeps your controller clean, and keeps all logic related to the user model within the user model. This way, whichever way a user is created (from a web form, or from an API call, for example), we are guaranteed that the email will be sent.
108
+
109
+ Let's see how we would go about wiring it up using an observer.
110
+
111
+ First off, we need to create a simple +User+ scaffold:
112
+
113
+ <shell>
114
+ $ script/generate scaffold user name:string email:string login:string
115
+ $ rake db:migrate
116
+ </shell>
117
+
118
+ Now that we have a user model to play with, edit +config/application.rb+ and register the observer:
119
+
120
+ <ruby>
121
+ module MailerGuideCode
122
+ class Application < Rails::Application
123
+ # ...
124
+ config.active_record.observers = :user_observer
125
+ end
126
+ end
127
+ </ruby>
128
+
129
+ You can make a +app/observers+ directory and Rails will automatically load it for you (Rails will automatically load anything in the +app+ directory as of version 3.0)
130
+
131
+ Now create a file called +user_observer.rb+ in +app/observers+ and make it look like:
132
+
133
+ <ruby>
134
+ class UserObserver < ActiveRecord::Observer
135
+ def after_create(user)
136
+ UserMailer.welcome_email(user).deliver
137
+ end
138
+ end
139
+ </ruby>
140
+
141
+ Notice how we call <tt>UserMailer.welcome_email(user)</tt>? Even though in the <tt>user_mailer.rb</tt> file we defined an instance method, we are calling the method_name +welcome_email(user)+ on the class. This is a peculiarity of Action Mailer.
142
+
143
+ NOTE: In previous versions of Rails, you would call +deliver_welcome_email+ or +create_welcome_email+ however in Rails 3.0 this has been deprecated in favour of just calling the method name itself.
144
+
145
+ The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out.
146
+
147
+
148
+ h4. Complete List of Action Mailer Methods
149
+
150
+ There are just three methods that you need to send pretty much any email message:
151
+
152
+ * <tt>headers</tt> - Specifies any header on the email you want, you can pass a hash of header field names and value pairs, or you can call <tt>headers[:field_name] = 'value'</tt>
153
+ * <tt>attachments</tt> - Allows you to add attachments to your email, for example <tt>attachments['file-name.jpg'] = File.read('file-name.jpg')</tt>
154
+ * <tt>mail</tt> - Sends the actual email itself. You can pass in headers as a hash to the mail method as a parameter, mail will then create an email, either plain text, or multipart, depending on what email templates you have defined.
155
+
156
+ h5. Custom Headers
157
+
158
+ Defining custom headers are simple, you can do it one of three ways:
159
+
160
+ * Defining a header field as a parameter to the +mail+ method:
161
+
162
+ <ruby>
163
+ mail(:x_spam => value)
164
+ </ruby>
165
+
166
+ * Passing in a key value assignment to the +headers+ method:
167
+
168
+ <ruby>
169
+ headers[:x_spam] = value
170
+ </ruby>
171
+
172
+ * Passing a hash of key value pairs to the +headers+ method:
173
+
174
+ <ruby>
175
+ headers {:x_spam => value, :x_special => another_value}
176
+ </ruby>
177
+
178
+ h5. Adding Attachments
179
+
180
+ Adding attachments has been simplified in Action Mailer 3.0.
181
+
182
+ * Pass the file name and content and Action Mailer and the Mail gem will automatically guess the mime_type, set the encoding and create the attachment.
183
+
184
+ <ruby>
185
+ attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
186
+ </ruby>
187
+
188
+ 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.
189
+
190
+ * Pass the file name and specify headers and content and Action Mailer and Mail will use the settings you pass in.
191
+
192
+ <ruby>
193
+ encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
194
+ attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
195
+ :encoding => 'SpecialEncoding',
196
+ :content => encoded_content }
197
+ </ruby>
198
+
199
+ NOTE: If you specify an encoding, Mail will assume that your content is already encoded and not try to Base64 encode it.
200
+
201
+ h4. Mailer Views
202
+
203
+ Mailer views are located in the +app/views/name_of_mailer_class+ directory. The specific mailer view is known to the class because it's name is the same as the mailer method. So for example, 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.
204
+
205
+ To change the default mailer view for your action you do something like:
206
+
207
+ <ruby>
208
+ class UserMailer < ActionMailer::Base
209
+ default :from => "notifications@example.com"
210
+
211
+ def welcome_email(user)
212
+ @user = user
213
+ @url = "http://example.com/login"
214
+ mail(:to => user.email,
215
+ :subject => "Welcome to My Awesome Site") do |format|
216
+ format.html { render 'another_template' }
217
+ format.text { render 'another_template' }
218
+ end
219
+ end
220
+
221
+ end
222
+ </ruby>
223
+
224
+ Will render 'another_template.text.erb' and 'another_template.html.erb'. The render command is the same one used inside of Action Controller, so you can use all the same options, such as <tt>:text</tt> etc.
225
+
226
+ h4. Action Mailer Layouts
227
+
228
+ Just like controller views, you can also have mailer layouts. The layout name needs to be the same as your mailer, such as +user_mailer.html.erb+ and +user_mailer.text.erb+ to be automatically recognized by your mailer as a layout.
229
+
230
+ In order to use a different file just use:
231
+
232
+ <ruby>
233
+ class UserMailer < ActionMailer::Base
234
+ layout 'awesome' # use awesome.(html|text).erb as the layout
235
+ end
236
+ </ruby>
237
+
238
+ Just like with controller views, use +yield+ to render the view inside the layout.
239
+
240
+ You can also pass in a <tt>:layout => 'layout_name'</tt> option to the render call inside the format block to specify different layouts for different actions:
241
+
242
+ <ruby>
243
+ class UserMailer < ActionMailer::Base
244
+ def welcome_email(user)
245
+ mail(:to => user.email) do |format|
246
+ format.html { render :layout => 'my_layout' }
247
+ format.text
248
+ end
249
+ end
250
+ end
251
+ </ruby>
252
+
253
+ Will render the HTML part using the <tt>my_layout.html.erb</tt> file and the text part with the usual <tt>user_mailer.text.erb</tt> file if it exists.
254
+
255
+ h4. Generating URLs in Action Mailer Views
256
+
257
+ URLs can be generated in mailer views using +url_for+ or named routes.
258
+
259
+ Unlike controllers, the mailer instance doesn't have any context about the incoming request so you'll need to provide the +:host+, +:controller+, and +:action+:
260
+
261
+ <erb>
262
+ <%= url_for(:host => "example.com",
263
+ :controller => "welcome",
264
+ :action => "greeting") %>
265
+ </erb>
266
+
267
+ When using named routes you only need to supply the +:host+:
268
+
269
+ <erb>
270
+ <%= user_url(@user, :host => "example.com") %>
271
+ </erb>
272
+
273
+ Email clients have no web context and so paths have no base URL to form complete web addresses. Thus, when using named routes only the "_url" variant makes sense.
274
+
275
+ It is also possible to set a default host that will be used in all mailers by setting the +:host+ option in the +ActionMailer::Base.default_url_options+ hash as follows:
276
+
277
+ <ruby>
278
+ class UserMailer < ActionMailer::Base
279
+ default_url_options[:host] = "example.com"
280
+
281
+ def welcome_email(user)
282
+ @user = user
283
+ @url = user_url(@user)
284
+ mail(:to => user.email,
285
+ :subject => "Welcome to My Awesome Site")
286
+ end
287
+ end
288
+ </ruby>
289
+
290
+ h4. Sending Multipart Emails
291
+
292
+ Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.
293
+
294
+ The order of the parts getting inserted is determined by the <tt>:parts_order</tt> inside of the <tt>ActionMailer::Base.default</tt> method. If you want to explicitly alter the order, you can either change the <tt>:parts_order</tt> or explicitly render the parts in a different order:
295
+
296
+ <ruby>
297
+ class UserMailer < ActionMailer::Base
298
+ def welcome_email(user)
299
+ @user = user
300
+ @url = user_url(@user)
301
+ mail(:to => user.email,
302
+ :subject => "Welcome to My Awesome Site") do |format|
303
+ format.html
304
+ format.text
305
+ end
306
+ end
307
+ end
308
+ </ruby>
309
+
310
+ Will put the HTML part first, and the plain text part second.
311
+
312
+ h4. Sending Emails with Attachments
313
+
314
+ Attachments can be added by using the +attachment+ method:
315
+
316
+ <ruby>
317
+ class UserMailer < ActionMailer::Base
318
+ def welcome_email(user)
319
+ @user = user
320
+ @url = user_url(@user)
321
+ attachments['terms.pdf'] = File.read('/path/terms.pdf')
322
+ mail(:to => user.email,
323
+ :subject => "Please see the Terms and Conditions attached")
324
+ end
325
+ end
326
+ </ruby>
327
+
328
+ The above will send a multipart email with an attachment, properly nested with the top level being <tt>mixed/multipart</tt> and the first part being a <tt>mixed/alternative</tt> containing the plain text and HTML email messages.
329
+
330
+ h3. Receiving Emails
331
+
332
+ 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:
333
+
334
+ * Implement a +receive+ method in your mailer.
335
+
336
+ * Configure your email server to forward emails from the address(es) you would like your app to receive to +/path/to/app/script/runner 'UserMailer.receive(STDIN.read)'+.
337
+
338
+ Once a method called +receive+ is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer +receive+ instance method. Here's an example:
339
+
340
+ <ruby>
341
+ class UserMailer < ActionMailer::Base
342
+ def receive(email)
343
+ page = Page.find_by_address(email.to.first)
344
+ page.emails.create(
345
+ :subject => email.subject,
346
+ :body => email.body
347
+ )
348
+
349
+ if email.has_attachments?
350
+ for attachment in email.attachments
351
+ page.attachments.create({
352
+ :file => attachment,
353
+ :description => email.subject
354
+ })
355
+ end
356
+ end
357
+ end
358
+ end
359
+ </ruby>
360
+
361
+ h3. Using Action Mailer Helpers
362
+
363
+ Action Mailer now just inherits from Abstract Controller, so you have access to the same generic helpers as you do in Action Controller.
364
+
365
+ h3. Action Mailer Configuration
366
+
367
+ The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...)
368
+
369
+ |template_root|Determines the base from which template references will be made.|
370
+ |logger|the logger is used for generating information on the mailing run if available. Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.|
371
+ |smtp_settings|Allows detailed configuration for :smtp delivery method: :address - Allows you to use a remote mail server. Just change it from its default "localhost" setting. :port - On the off chance that your mail server doesn't run on port 25, you can change it. :domain - If you need to specify a HELO domain, you can do it here. :user_name - If your mail server requires authentication, set the username in this setting. :password - If your mail server requires authentication, set the password in this setting. :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.|
372
+ |sendmail_settings|Allows you to override options for the :sendmail delivery method. :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail. :arguments - The command line arguments. Defaults to -i -t.|
373
+ |raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.|
374
+ |delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.|
375
+ |perform_deliveries|Determines whether deliver_* methods are actually carried out. By default they are, but this can be turned off to help functional testing.|
376
+ |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.|
377
+
378
+ h4. Example Action Mailer Configuration
379
+
380
+ An example would be adding the following to your appropriate <tt>config/environments/env.rb</tt> file:
381
+
382
+ <ruby>
383
+ config.action_mailer.delivery_method = :sendmail
384
+ # Defaults to:
385
+ # config.action_mailer.sendmail_settings = {
386
+ # :location => '/usr/sbin/sendmail',
387
+ # :arguments => '-i -t'
388
+ # }
389
+ config.action_mailer.perform_deliveries = true
390
+ config.action_mailer.raise_delivery_errors = true
391
+ </ruby>
392
+
393
+ h4. Action Mailer Configuration for GMail
394
+
395
+ As Action Mailer now uses the Mail gem, this becomes as simple as adding to your <tt>config/environments/env.rb</tt> file:
396
+
397
+ <ruby>
398
+ config.action_mailer.delivery_method = :smtp
399
+ config.action_mailer.smtp_settings = {
400
+ :address => "smtp.gmail.com",
401
+ :port => 587,
402
+ :domain => 'baci.lindsaar.net',
403
+ :user_name => '<username>',
404
+ :password => '<password>',
405
+ :authentication => 'plain',
406
+ :enable_starttls_auto => true }
407
+ </ruby>
408
+
409
+ h3. Mailer Testing
410
+
411
+ By default Action Mailer does not send emails in the test environment. They are just added to the +ActionMailer::Base.deliveries+ array.
412
+
413
+ Testing mailers normally involves two things: One is that the mail was queued, and the other one that the email is correct. With that in mind, we could test our example mailer from above like so:
414
+
415
+ <ruby>
416
+ class UserMailerTest < ActionMailer::TestCase
417
+ def test_welcome_email
418
+ user = users(:some_user_in_your_fixtures)
419
+
420
+ # Send the email, then test that it got queued
421
+ email = UserMailer.deliver_welcome_email(user)
422
+ assert !ActionMailer::Base.deliveries.empty?
423
+
424
+ # Test the body of the sent email contains what we expect it to
425
+ assert_equal [user.email], email.to
426
+ assert_equal "Welcome to My Awesome Site", email.subject
427
+ assert_match /<h1>Welcome to example.com, #{user.name}<\/h1>/, email.encoded
428
+ assert_match /Welcome to example.com, #{user.name}/, email.encoded
429
+ end
430
+ end
431
+ </ruby>
432
+
433
+ In the test we send the email and store the returned object in the +email+ variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain the what we expect.
434
+
435
+ h3. Changelog
436
+
437
+ "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213/tickets/25
@@ -0,0 +1,1481 @@
1
+ h2. Action View Overview
2
+
3
+ In this guide you will learn:
4
+
5
+ * What Action View is, and how to use it with Rails
6
+ * How to use Action View outside of Rails
7
+ * How best to use templates, partials, and layouts
8
+ * What helpers are provided by Action View, and how to make your own
9
+ * How to use localized views
10
+
11
+ endprologue.
12
+
13
+ h3. What is Action View?
14
+
15
+ Action View and Action Controller are the two major components of Action Pack. In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template). Typically, Action Controller will be concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.
16
+
17
+ Action View templates are written using embedded Ruby in tags mingled with HTML. To avoid cluttering the templates with boilerplate code, a number of helper classes provide common behavior for forms, dates, and strings. It's also easy to add new helpers to your application as it evolves.
18
+
19
+ Note: Some features of Action View are tied to Active Record, but that doesn't mean that Action View depends on Active Record. Action View is an independent package that can be used with any sort of backend.
20
+
21
+ h3. Using Action View with Rails
22
+
23
+ TODO...
24
+
25
+ h3. Using Action View outside of Rails
26
+
27
+ Action View works well with Action Record, but it can also be used with other Ruby tools. We can demonstrate this by creating a small "Rack":http://rack.rubyforge.org/ application that includes Action View functionality. This may be useful, for example, if you'd like access to Action View's helpers in a Rack application.
28
+
29
+ Let's start by ensuring that you have the Action Pack and Rack gems installed:
30
+
31
+ <shell>
32
+ gem install actionpack
33
+ gem install rack
34
+ </shell>
35
+
36
+ Now we'll create a simple "Hello World" application that uses the +titleize+ method provided by Action View.
37
+
38
+ *hello_world.rb:*
39
+
40
+ <ruby>
41
+ require 'rubygems'
42
+ require 'action_view'
43
+ require 'rack'
44
+
45
+ def hello_world(env)
46
+ [200, {"Content-Type" => "text/html"}, "hello world".titleize]
47
+ end
48
+
49
+ Rack::Handler::Mongrel.run method(:hello_world), :Port => 4567
50
+ </ruby>
51
+
52
+ We can see this all come together by starting up the application and then visiting +http://localhost:4567/+
53
+
54
+ <shell>
55
+ ruby hello_world.rb
56
+ </shell>
57
+
58
+ TODO needs a screenshot? I have one - not sure where to put it.
59
+
60
+ Notice how 'hello world' has been converted into 'Hello World' by the +titleize+ helper method.
61
+
62
+ Action View can also be used with "Sinatra":http://www.sinatrarb.com/ in the same way.
63
+
64
+ Let's start by ensuring that you have the Action Pack and Sinatra gems installed:
65
+
66
+ <shell>
67
+ gem install actionpack
68
+ gem install sinatra
69
+ </shell>
70
+
71
+ Now we'll create the same "Hello World" application in Sinatra.
72
+
73
+ *hello_world.rb:*
74
+
75
+ <ruby>
76
+ require 'rubygems'
77
+ require 'action_view'
78
+ require 'sinatra'
79
+
80
+ get '/' do
81
+ erb 'hello world'.titleize
82
+ end
83
+ </ruby>
84
+
85
+ Then, we can run the application:
86
+
87
+ <shell>
88
+ ruby hello_world.rb
89
+ </shell>
90
+
91
+ Once the application is running, you can see Sinatra and Action View working together by visiting +http://localhost:4567/+
92
+
93
+ TODO needs a screenshot? I have one - not sure where to put it.
94
+
95
+ h3. Templates, Partials and Layouts
96
+
97
+ TODO...
98
+
99
+ TODO see http://guides.rubyonrails.org/layouts_and_rendering.html
100
+
101
+ h3. Using Templates, Partials and Layouts in "The Rails Way"
102
+
103
+ TODO...
104
+
105
+ h3. Partial Layouts
106
+
107
+ Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally for the entire action, but they work in a similar fashion.
108
+
109
+ Let's say we're displaying a post on a page where it should be wrapped in a +div+ for display purposes. First, we'll create a new +Post+:
110
+
111
+ <ruby>
112
+ Post.create(:body => 'Partial Layouts are cool!')
113
+ </ruby>
114
+
115
+ In the +show+ template, we'll render the +post+ partial wrapped in the +box+ layout:
116
+
117
+ *posts/show.html.erb*
118
+
119
+ <ruby>
120
+ <%= render :partial => 'post', :layout => 'box', :locals => {:post => @post} %>
121
+ </ruby>
122
+
123
+ The +box+ layout simply wraps the +post+ partial in a +div+:
124
+
125
+ *posts/_box.html.erb*
126
+
127
+ <ruby>
128
+ <div class='box'>
129
+ <%= yield %>
130
+ </div>
131
+ </ruby>
132
+
133
+ The +post+ partial wraps the post's +body+ in a +div+ with the +id+ of the post using the +div_for+ helper:
134
+
135
+ *posts/_post.html.erb*
136
+
137
+ <ruby>
138
+ <% div_for(post) do %>
139
+ <p><%= post.body %></p>
140
+ <% end %>
141
+ </ruby>
142
+
143
+ This example would output the following:
144
+
145
+ <html>
146
+ <div class='box'>
147
+ <div id='post_1'>
148
+ <p>Partial Layouts are cool!</p>
149
+ </div>
150
+ </div>
151
+ </html>
152
+
153
+ Note that the partial layout has access to the local +post+ variable that was passed into the +render+ call. However, unlike application-wide layouts, partial layouts still have the underscore prefix.
154
+
155
+ You can also render a block of code within a partial layout instead of calling +yield+. For example, if we didn't have the +post+ partial, we could do this instead:
156
+
157
+ *posts/show.html.erb*
158
+
159
+ <ruby>
160
+ <% render(:layout => 'box', :locals => {:post => @post}) do %>
161
+ <% div_for(post) do %>
162
+ <p><%= post.body %></p>
163
+ <% end %>
164
+ <% end %>
165
+ </ruby>
166
+
167
+ If we're using the same +box+ partial from above, his would produce the same output as the previous example.
168
+
169
+ h3. View Paths
170
+
171
+ TODO...
172
+
173
+ h3. Overview of all the helpers provided by Action View
174
+
175
+ The following is only a brief overview summary of the helpers available in Action View. It's recommended that you review the API Documentation, which covers all of the helpers in more detail, but this should serve as a good starting point.
176
+
177
+ h4. ActiveRecordHelper
178
+
179
+ The Active Record Helper makes it easier to create forms for records kept in instance variables. You may also want to review the "Rails Form helpers guide":form_helpers.html.
180
+
181
+ h5. error_message_on
182
+
183
+ Returns a string containing the error message attached to the method on the object if one exists.
184
+
185
+ <ruby>
186
+ error_message_on "post", "title"
187
+ </ruby>
188
+
189
+ h5. error_messages_for
190
+
191
+ Returns a string with a DIV containing all of the error messages for the objects located as instance variables by the names given.
192
+
193
+ <ruby>
194
+ error_messages_for "post"
195
+ </ruby>
196
+
197
+ h5. form
198
+
199
+ Returns a form with inputs for all attributes of the specified Active Record object. For example, let's say we have a +@post+ with attributes named +title+ of type +String+ and +body+ of type +Text+. Calling +form+ would produce a form to creating a new post with inputs for those attributes.
200
+
201
+ <ruby>
202
+ form("post")
203
+ </ruby>
204
+
205
+ <html>
206
+ <form action='/posts/create' method='post'>
207
+ <p>
208
+ <label for="post_title">Title</label><br />
209
+ <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
210
+ </p>
211
+ <p>
212
+ <label for="post_body">Body</label><br />
213
+ <textarea cols="40" id="post_body" name="post[body]" rows="20"></textarea>
214
+ </p>
215
+ <input name="commit" type="submit" value="Create" />
216
+ </form>
217
+ </html>
218
+
219
+ Typically, +form_for+ is used instead of +form+ because it doesn't automatically include all of the model's attributes.
220
+
221
+ h5. input
222
+
223
+ Returns a default input tag for the type of object returned by the method.
224
+
225
+ For example, if +@post+ has an attribute +title+ mapped to a +String+ column that holds "Hello World":
226
+
227
+ <ruby>
228
+ input("post", "title") # =>
229
+ <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
230
+ </ruby>
231
+
232
+ h4. AssetTagHelper
233
+
234
+ This module provides methods for generating HTML that links views to assets such as images, javascripts, stylesheets, and feeds.
235
+
236
+ 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 your +config/environment.rb+. For example, let's say your asset host is +assets.example.com+:
237
+
238
+ <ruby>
239
+ ActionController::Base.asset_host = "assets.example.com"
240
+ image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
241
+ </ruby>
242
+
243
+ h5. register_javascript_expansion
244
+
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.
246
+
247
+ <ruby>
248
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey => ["head", "body", "tail"]
249
+
250
+ javascript_include_tag :monkey # =>
251
+ <script type="text/javascript" src="/javascripts/head.js"></script>
252
+ <script type="text/javascript" src="/javascripts/body.js"></script>
253
+ <script type="text/javascript" src="/javascripts/tail.js"></script>
254
+ </ruby>
255
+
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
+
260
+ h5. register_stylesheet_expansion
261
+
262
+ Register one or more stylesheet files to be included when symbol is passed to +stylesheet_link_tag+. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in +public/stylesheets+.
263
+
264
+ <ruby>
265
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey => ["head", "body", "tail"]
266
+
267
+ 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" />
271
+ </ruby>
272
+
273
+ h5. auto_discovery_link_tag
274
+
275
+ Returns a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.
276
+
277
+ <ruby>
278
+ auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "RSS Feed"}) # =>
279
+ <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed" />
280
+ </ruby>
281
+
282
+ h5. image_path
283
+
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.
285
+
286
+ <ruby>
287
+ image_path("edit.png") # => /images/edit.png
288
+ </ruby>
289
+
290
+ h5. image_tag
291
+
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.
293
+
294
+ <ruby>
295
+ image_tag("icon.png") # => <img src="/images/icon.png" alt="Icon" />
296
+ </ruby>
297
+
298
+ h5. javascript_include_tag
299
+
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.
301
+
302
+ <ruby>
303
+ javascript_include_tag "common" # =>
304
+ <script type="text/javascript" src="/javascripts/common.js"></script>
305
+ </ruby>
306
+
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.
308
+
309
+ <ruby>
310
+ javascript_include_tag :defaults
311
+ </ruby>
312
+
313
+ You can also include all javascripts in the javascripts directory using +:all+ as the source.
314
+
315
+ <ruby>
316
+ javascript_include_tag :all
317
+ </ruby>
318
+
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).
320
+
321
+ <ruby>
322
+ javascript_include_tag :all, :cache => true # =>
323
+ <script type="text/javascript" src="/javascripts/all.js"></script>
324
+ </ruby>
325
+
326
+ h5. javascript_path
327
+
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.
329
+
330
+ <ruby>
331
+ javascript_path "common" # => /javascripts/common.js
332
+ </ruby>
333
+
334
+ h5. stylesheet_link_tag
335
+
336
+ Returns a stylesheet link tag for the sources specified as arguments. If you don't specify an extension, +.css+ will be appended automatically.
337
+
338
+ <ruby>
339
+ stylesheet_link_tag "application" # =>
340
+ <link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
341
+ </ruby>
342
+
343
+ You can also include all styles in the stylesheet directory using :all as the source:
344
+
345
+ <ruby>
346
+ stylesheet_link_tag :all
347
+ </ruby>
348
+
349
+ You can also cache multiple stylesheets into one file, which requires less HTTP connections 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).
350
+
351
+ <ruby>
352
+ stylesheet_link_tag :all, :cache => true
353
+ <link href="/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />
354
+ </ruby>
355
+
356
+ h5. stylesheet_path
357
+
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.
359
+
360
+ <ruby>
361
+ stylesheet_path "application" # => /stylesheets/application.css
362
+ </ruby>
363
+
364
+ h4. AtomFeedHelper
365
+
366
+ h5. atom_feed
367
+
368
+ This helper makes building an ATOM feed easy. Here's a full usage example:
369
+
370
+ *config/routes.rb*
371
+
372
+ <ruby>
373
+ map.resources :posts
374
+ </ruby>
375
+
376
+ *app/controllers/posts_controller.rb*
377
+
378
+ <ruby>
379
+ def index
380
+ @posts = Post.find(:all)
381
+
382
+ respond_to do |format|
383
+ format.html
384
+ format.atom
385
+ end
386
+ end
387
+ </ruby>
388
+
389
+ *app/views/posts/index.atom.builder*
390
+
391
+ <ruby>
392
+ atom_feed do |feed|
393
+ feed.title("Posts Index")
394
+ feed.updated((@posts.first.created_at))
395
+
396
+ for post in @posts
397
+ feed.entry(post) do |entry|
398
+ entry.title(post.title)
399
+ entry.content(post.body, :type => 'html')
400
+
401
+ entry.author do |author|
402
+ author.name(post.author_name)
403
+ end
404
+ end
405
+ end
406
+ end
407
+ </ruby>
408
+
409
+ h4. BenchmarkHelper
410
+
411
+ h5. benchmark
412
+
413
+ Allows you to measure the execution time of a block in a template and records the result to the log. Wrap this block around expensive operations or possible bottlenecks to get a time reading for the operation.
414
+
415
+ <ruby>
416
+ <% benchmark "Process data files" do %>
417
+ <%= expensive_files_operation %>
418
+ <% end %>
419
+ </ruby>
420
+
421
+ This would add something like "Process data files (0.34523)" to the log, which you can then use to compare timings when optimizing your code.
422
+
423
+ h4. CacheHelper
424
+
425
+ h5. cache
426
+
427
+ A method for caching fragments of a view rather than an entire action or page. This technique is useful caching pieces like menus, lists of news topics, static HTML fragments, and so on. This method takes a block that contains the content you wish to cache. See +ActionController::Caching::Fragments+ for more information.
428
+
429
+ <ruby>
430
+ <% cache do %>
431
+ <%= render :partial => "shared/footer" %>
432
+ <% end %>
433
+ </ruby>
434
+
435
+ h4. CaptureHelper
436
+
437
+ h5. capture
438
+
439
+ The +capture+ method allows you to extract part of a template into a variable. You can then use this variable anywhere in your templates or layout.
440
+
441
+ <ruby>
442
+ <% @greeting = capture do %>
443
+ <p>Welcome! The date and time is <%= Time.now %></p>
444
+ <% end %>
445
+ <ruby>
446
+
447
+ The captured variable can then be used anywhere else.
448
+
449
+ <ruby>
450
+ <html>
451
+ <head>
452
+ <title>Welcome!</title>
453
+ </head>
454
+ <body>
455
+ <%= @greeting %>
456
+ </body>
457
+ </html>
458
+ </ruby>
459
+
460
+ h5. content_for
461
+
462
+ Calling +content_for+ stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates or the layout by passing the identifier as an argument to +yield+.
463
+
464
+ For example, let's say we have a standard application layout, but also a special page that requires certain Javascript that the rest of the site doesn't need. We can use +content_for+ to include this Javascript on our special page without fattening up the rest of the site.
465
+
466
+ *app/views/layouts/application.html.erb*
467
+
468
+ <ruby>
469
+ <html>
470
+ <head>
471
+ <title>Welcome!</title>
472
+ <%= yield :special_script %>
473
+ </head>
474
+ <body>
475
+ <p>Welcome! The date and time is <%= Time.now %></p>
476
+ </body>
477
+ </html>
478
+ </ruby>
479
+
480
+ *app/views/posts/special.html.erb*
481
+
482
+ <ruby>
483
+ <p>This is a special page.</p>
484
+
485
+ <% content_for :special_script do %>
486
+ <script type="text/javascript">alert('Hello!')</script>
487
+ <% end %>
488
+ </ruby>
489
+
490
+ h4. DateHelper
491
+
492
+ h5. date_select
493
+
494
+ Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute.
495
+
496
+ <ruby>
497
+ date_select("post", "published_on")
498
+ </ruby>
499
+
500
+ h5. datetime_select
501
+
502
+ Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute.
503
+
504
+ <ruby>
505
+ datetime_select("post", "published_on")
506
+ </ruby>
507
+
508
+ h5. distance_of_time_in_words
509
+
510
+ Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set +include_seconds+ to true if you want more detailed approximations.
511
+
512
+ <ruby>
513
+ distance_of_time_in_words(Time.now, Time.now + 15.seconds) # => less than a minute
514
+ distance_of_time_in_words(Time.now, Time.now + 15.seconds, true) # => less than 20 seconds
515
+ </ruby>
516
+
517
+ h5. select_date
518
+
519
+ Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+ provided.
520
+
521
+ <ruby>
522
+ # Generates a date select that defaults to the date provided (six days after today)
523
+ select_date(Time.today + 6.days)
524
+
525
+ # Generates a date select that defaults to today (no specified date)
526
+ select_date()
527
+ </ruby>
528
+
529
+ h5. select_datetime
530
+
531
+ Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the +datetime+ provided.
532
+
533
+ <ruby>
534
+ # Generates a datetime select that defaults to the datetime provided (four days after today)
535
+ select_datetime(Time.now + 4.days)
536
+
537
+ # Generates a datetime select that defaults to today (no specified datetime)
538
+ select_datetime()
539
+ </ruby>
540
+
541
+ h5. select_day
542
+
543
+ Returns a select tag with options for each of the days 1 through 31 with the current day selected.
544
+
545
+ <ruby>
546
+ # Generates a select field for days that defaults to the day for the date provided
547
+ select_day(Time.today + 2.days)
548
+
549
+ # Generates a select field for days that defaults to the number given
550
+ select_day(5)
551
+ </ruby>
552
+
553
+ h5. select_hour
554
+
555
+ Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.
556
+
557
+ <ruby>
558
+ # Generates a select field for minutes that defaults to the minutes for the time provided
559
+ select_minute(Time.now + 6.hours)
560
+ </ruby>
561
+
562
+ h5. select_minute
563
+
564
+ Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.
565
+
566
+ <ruby>
567
+ # Generates a select field for minutes that defaults to the minutes for the time provided.
568
+ select_minute(Time.now + 6.hours)
569
+ </ruby>
570
+
571
+ h5. select_month
572
+
573
+ Returns a select tag with options for each of the months January through December with the current month selected.
574
+
575
+ <ruby>
576
+ # Generates a select field for months that defaults to the current month
577
+ select_month(Date.today)
578
+ </ruby>
579
+
580
+ h5. select_second
581
+
582
+ Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.
583
+
584
+ <ruby>
585
+ # Generates a select field for seconds that defaults to the seconds for the time provided
586
+ select_second(Time.now + 16.minutes)
587
+ </ruby>
588
+
589
+ h5. select_time
590
+
591
+ Returns a set of html select-tags (one for hour and minute).
592
+
593
+ <ruby>
594
+ # Generates a time select that defaults to the time provided
595
+ select_time(Time.now)
596
+ </ruby>
597
+
598
+ h5. select_year
599
+
600
+ Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius can be changed using the +:start_year+ and +:end_year+ keys in the +options+.
601
+
602
+ <ruby>
603
+ # Generates a select field for five years on either side of +Date.today+ that defaults to the current year
604
+ select_year(Date.today)
605
+
606
+ # Generates a select field from 1900 to 2009 that defaults to the current year
607
+ select_year(Date.today, :start_year => 1900, :end_year => 2009)
608
+ </ruby>
609
+
610
+ h5. time_ago_in_words
611
+
612
+ Like +distance_of_time_in_words+, but where +to_time+ is fixed to +Time.now+.
613
+
614
+ <ruby>
615
+ time_ago_in_words(3.minutes.from_now) # => 3 minutes
616
+ </ruby>
617
+
618
+ h5. time_select
619
+
620
+ Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute. The selects are prepared for multi-parameter assignment to an Active Record object.
621
+
622
+ <ruby>
623
+ # Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted attribute
624
+ time_select("order", "submitted")
625
+ </ruby>
626
+
627
+ h4. DebugHelper
628
+
629
+ Returns a +pre+ tag that has object dumped by YAML. This creates a very readable way to inspect an object.
630
+
631
+ <ruby>
632
+ my_hash = {'first' => 1, 'second' => 'two', 'third' => [1,2,3]}
633
+ debug(my_hash)
634
+ </ruby>
635
+
636
+ <html>
637
+ <pre class='debug_dump'>---
638
+ first: 1
639
+ second: two
640
+ third:
641
+ - 1
642
+ - 2
643
+ - 3
644
+ </pre>
645
+ </html>
646
+
647
+ h4. FormHelper
648
+
649
+ Form helpers are designed to make working with models much easier compared to using just standard HTML elements by providing a set of methods for creating forms based on your models. This helper generates the HTML for forms, providing a method for each sort of input (e.g., text, password, select, and so on). When the form is submitted (i.e., when the user hits the submit button or form.submit is called via JavaScript), the form inputs will be bundled into the params object and passed back to the controller.
650
+
651
+ There are two types of form helpers: those that specifically work with model attributes and those that don't. This helper deals with those that work with model attributes; to see an example of form helpers that don‘t work with model attributes, check the ActionView::Helpers::FormTagHelper documentation.
652
+
653
+ The core method of this helper, form_for, gives you the ability to create a form for a model instance; for example, let's say that you have a model Person and want to create a new instance of it:
654
+
655
+ <ruby>
656
+ # 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| %>
658
+ <%= f.text_field :first_name %>
659
+ <%= f.text_field :last_name %>
660
+ <%= submit_tag 'Create' %>
661
+ <% end %>
662
+ </ruby>
663
+
664
+ The HTML generated for this would be:
665
+
666
+ <html>
667
+ <form action="/persons/create" method="post">
668
+ <input id="person_first_name" name="person[first_name]" size="30" type="text" />
669
+ <input id="person_last_name" name="person[last_name]" size="30" type="text" />
670
+ <input name="commit" type="submit" value="Create" />
671
+ </form>
672
+ </html>
673
+
674
+ The params object created when this form is submitted would look like:
675
+
676
+ <ruby>
677
+ {"action"=>"create", "controller"=>"persons", "person"=>{"first_name"=>"William", "last_name"=>"Smith"}}
678
+ </ruby>
679
+
680
+ The params hash has a nested person value, which can therefore be accessed with params[:person] in the controller.
681
+
682
+ h5. check_box
683
+
684
+ Returns a checkbox tag tailored for accessing a specified attribute.
685
+
686
+ <ruby>
687
+ # Let's say that @post.validated? is 1:
688
+ check_box("post", "validated")
689
+ # => <input type="checkbox" id="post_validated" name="post[validated]" value="1" />
690
+ # <input name="post[validated]" type="hidden" value="0" />
691
+ </ruby>
692
+
693
+ h5. fields_for
694
+
695
+ Creates a scope around a specific model object like form_for, but doesn‘t create the form tags themselves. This makes fields_for suitable for specifying additional model objects in the same form:
696
+
697
+ <ruby>
698
+ <% form_for @person, :url => { :action => "update" } do |person_form| %>
699
+ First name: <%= person_form.text_field :first_name %>
700
+ Last name : <%= person_form.text_field :last_name %>
701
+
702
+ <% fields_for @person.permission do |permission_fields| %>
703
+ Admin? : <%= permission_fields.check_box :admin %>
704
+ <% end %>
705
+ <% end %>
706
+ </ruby>
707
+
708
+ h5. file_field
709
+
710
+ Returns an file upload input tag tailored for accessing a specified attribute.
711
+
712
+ <ruby>
713
+ file_field(:user, :avatar)
714
+ # => <input type="file" id="user_avatar" name="user[avatar]" />
715
+ </ruby>
716
+
717
+ h5. form_for
718
+
719
+ Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.
720
+
721
+ <ruby>
722
+ <% form_for @post do |f| %>
723
+ <%= f.label :title, 'Title' %>:
724
+ <%= f.text_field :title %><br />
725
+ <%= f.label :body, 'Body' %>:
726
+ <%= f.text_area :body %><br />
727
+ <% end %>
728
+ </ruby>
729
+
730
+ h5. hidden_field
731
+
732
+ Returns a hidden input tag tailored for accessing a specified attribute.
733
+
734
+ <ruby>
735
+ hidden_field(:user, :token)
736
+ # => <input type="hidden" id="user_token" name="user[token]" value="#{@user.token}" />
737
+ </ruby>
738
+
739
+ h5. label
740
+
741
+ Returns a label tag tailored for labelling an input field for a specified attribute.
742
+
743
+ <ruby>
744
+ label(:post, :title)
745
+ # => <label for="post_title">Title</label>
746
+ </ruby>
747
+
748
+ h5. password_field
749
+
750
+ Returns an input tag of the "password" type tailored for accessing a specified attribute.
751
+
752
+ <ruby>
753
+ password_field(:login, :pass)
754
+ # => <input type="text" id="login_pass" name="login[pass]" value="#{@login.pass}" />
755
+ </ruby>
756
+
757
+ h5. radio_button
758
+
759
+ Returns a radio button tag for accessing a specified attribute.
760
+
761
+ <ruby>
762
+ # Let's say that @post.category returns "rails":
763
+ radio_button("post", "category", "rails")
764
+ radio_button("post", "category", "java")
765
+ # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" />
766
+ # <input type="radio" id="post_category_java" name="post[category]" value="java" />
767
+ </ruby>
768
+
769
+ h5. text_area
770
+
771
+ Returns a textarea opening and closing tag set tailored for accessing a specified attribute.
772
+
773
+ <ruby>
774
+ text_area(:comment, :text, :size => "20x30")
775
+ # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
776
+ # #{@comment.text}
777
+ # </textarea>
778
+ </ruby>
779
+
780
+ h5. text_field
781
+
782
+ Returns an input tag of the "text" type tailored for accessing a specified attribute.
783
+
784
+ <ruby>
785
+ text_field(:post, :title)
786
+ # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" />
787
+ </ruby>
788
+
789
+ h4. FormOptionsHelper
790
+
791
+ Provides a number of methods for turning different kinds of containers into a set of option tags.
792
+
793
+ h5. collection_select
794
+
795
+ Returns +select+ and +option+ tags for the collection of existing return values of +method+ for +object+'s class.
796
+
797
+ Example object structure for use with this method:
798
+
799
+ <ruby>
800
+ class Post < ActiveRecord::Base
801
+ belongs_to :author
802
+ end
803
+
804
+ class Author < ActiveRecord::Base
805
+ has_many :posts
806
+ def name_with_initial
807
+ "#{first_name.first}. #{last_name}"
808
+ end
809
+ end
810
+ </ruby>
811
+
812
+ Sample usage (selecting the associated Author for an instance of Post, +@post+):
813
+
814
+ <ruby>
815
+ collection_select(:post, :author_id, Author.find(:all), :id, :name_with_initial, {:prompt => true})
816
+ </ruby>
817
+
818
+ If @post.author_id is already 1, this would return:
819
+
820
+ <html>
821
+ <select name="post[author_id]">
822
+ <option value="">Please select</option>
823
+ <option value="1" selected="selected">D. Heinemeier Hansson</option>
824
+ <option value="2">D. Thomas</option>
825
+ <option value="3">M. Clark</option>
826
+ </select>
827
+ </html>
828
+
829
+ h5. country_options_for_select
830
+
831
+ Returns a string of option tags for pretty much any country in the world.
832
+
833
+ h5. country_select
834
+
835
+ Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
836
+
837
+ h5. option_groups_from_collection_for_select
838
+
839
+ Returns a string of +option+ tags, like +options_from_collection_for_select+, but groups them by +optgroup+ tags based on the object relationships of the arguments.
840
+
841
+ Example object structure for use with this method:
842
+
843
+ <ruby>
844
+ class Continent < ActiveRecord::Base
845
+ has_many :countries
846
+ # attribs: id, name
847
+ end
848
+
849
+ class Country < ActiveRecord::Base
850
+ belongs_to :continent
851
+ # attribs: id, name, continent_id
852
+ end
853
+ </ruby>
854
+
855
+ Sample usage:
856
+
857
+ <ruby>
858
+ option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)
859
+ </ruby>
860
+
861
+ TODO check above textile output looks right
862
+
863
+ Possible output:
864
+
865
+ <html>
866
+ <optgroup label="Africa">
867
+ <option value="1">Egypt</option>
868
+ <option value="4">Rwanda</option>
869
+ ...
870
+ </optgroup>
871
+ <optgroup label="Asia">
872
+ <option value="3" selected="selected">China</option>
873
+ <option value="12">India</option>
874
+ <option value="5">Japan</option>
875
+ ...
876
+ </optgroup>
877
+ </html>
878
+
879
+ Note: Only the +optgroup+ and +option+ tags are returned, so you still have to wrap the output in an appropriate +select+ tag.
880
+
881
+ h5. options_for_select
882
+
883
+ Accepts a container (hash, array, enumerable, your type) and returns a string of option tags.
884
+
885
+ <ruby>
886
+ options_for_select([ "VISA", "MasterCard" ])
887
+ # => <option>VISA</option> <option>MasterCard</option>
888
+ </ruby>
889
+
890
+ Note: Only the +option+ tags are returned, you have to wrap this call in a regular HTML +select+ tag.
891
+
892
+ h5. options_from_collection_for_select
893
+
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.
895
+
896
+ <ruby>
897
+ # options_from_collection_for_select(collection, value_method, text_method, selected = nil)
898
+ </ruby>
899
+
900
+ For example, imagine a loop iterating over each person in @project.people to generate an input tag:
901
+
902
+ <ruby>
903
+ options_from_collection_for_select(@project.people, "id", "name")
904
+ # => <option value="#{person.id}">#{person.name}</option>
905
+ </ruby>
906
+
907
+ Note: Only the +option+ tags are returned, you have to wrap this call in a regular HTML +select+ tag.
908
+
909
+ h5. select
910
+
911
+ Create a select tag and a series of contained option tags for the provided object and method.
912
+
913
+ Example with @post.person_id => 1:
914
+
915
+ <ruby>
916
+ select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] }, { :include_blank => true })
917
+ </ruby>
918
+
919
+ could become:
920
+
921
+ <html>
922
+ <select name="post[person_id]">
923
+ <option value=""></option>
924
+ <option value="1" selected="selected">David</option>
925
+ <option value="2">Sam</option>
926
+ <option value="3">Tobias</option>
927
+ </select>
928
+ </html>
929
+
930
+ h5. time_zone_options_for_select
931
+
932
+ Returns a string of option tags for pretty much any time zone in the world.
933
+
934
+ h5. time_zone_select
935
+
936
+ Return select and option tags for the given object and method, using +time_zone_options_for_select+ to generate the list of option tags.
937
+
938
+ <ruby>
939
+ time_zone_select( "user", "time_zone")
940
+ </ruby>
941
+
942
+ h4. FormTagHelper
943
+
944
+ Provides a number of methods for creating form tags that doesn't rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.
945
+
946
+ h5. check_box_tag
947
+
948
+ Creates a check box form input tag.
949
+
950
+ <ruby>
951
+ check_box_tag 'accept'
952
+ # => <input id="accept" name="accept" type="checkbox" value="1" />
953
+ </ruby>
954
+
955
+ h5. field_set_tag
956
+
957
+ Creates a field set for grouping HTML form elements.
958
+
959
+ <ruby>
960
+ <% field_set_tag do %>
961
+ <p><%= text_field_tag 'name' %></p>
962
+ <% end %>
963
+ # => <fieldset><p><input id="name" name="name" type="text" /></p></fieldset>
964
+ </ruby>
965
+
966
+ h5. file_field_tag
967
+
968
+ Creates a file upload field.
969
+
970
+ If you are using file uploads then you will also need to set the multipart option for the form tag:
971
+
972
+ <ruby>
973
+ <%= form_tag { :action => "post" }, { :multipart => true } %>
974
+ <label for="file">File to Upload</label> <%= file_field_tag "file" %>
975
+ <%= submit_tag %>
976
+ <%= end_form_tag %>
977
+ </ruby>
978
+
979
+ Example output:
980
+
981
+ <ruby>
982
+ file_field_tag 'attachment'
983
+ # => <input id="attachment" name="attachment" type="file" />
984
+ </ruby>
985
+
986
+ h5. form_tag
987
+
988
+ Starts a form tag that points the action to an url configured with +url_for_options+ just like +ActionController::Base#url_for+.
989
+
990
+ <ruby>
991
+ <% form_tag '/posts' do -%>
992
+ <div><%= submit_tag 'Save' %></div>
993
+ <% end -%>
994
+ # => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
995
+ </ruby>
996
+
997
+ h5. hidden_field_tag
998
+
999
+ Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or data that should be hidden from the user.
1000
+
1001
+ <ruby>
1002
+ hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
1003
+ # => <input id="token" name="token" type="hidden" value="VUBJKB23UIVI1UU1VOBVI@" />
1004
+ </ruby>
1005
+
1006
+ h5. image_submit_tag
1007
+
1008
+ Displays an image which when clicked will submit the form.
1009
+
1010
+ <ruby>
1011
+ image_submit_tag("login.png")
1012
+ # => <input src="/images/login.png" type="image" />
1013
+ </ruby>
1014
+
1015
+ h5. label_tag
1016
+
1017
+ Creates a label field.
1018
+
1019
+ <ruby>
1020
+ label_tag 'name'
1021
+ # => <label for="name">Name</label>
1022
+ </ruby>
1023
+
1024
+ h5. password_field_tag
1025
+
1026
+ Creates a password field, a masked text field that will hide the users input behind a mask character.
1027
+
1028
+ <ruby>
1029
+ password_field_tag 'pass'
1030
+ # => <input id="pass" name="pass" type="password" />
1031
+ </ruby>
1032
+
1033
+ h5. radio_button_tag
1034
+
1035
+ Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.
1036
+
1037
+ <ruby>
1038
+ radio_button_tag 'gender', 'male'
1039
+ # => <input id="gender_male" name="gender" type="radio" value="male" />
1040
+ </ruby>
1041
+
1042
+ h5. select_tag
1043
+
1044
+ Creates a dropdown selection box.
1045
+
1046
+ <ruby>
1047
+ select_tag "people", "<option>David</option>"
1048
+ # => <select id="people" name="people"><option>David</option></select>
1049
+ </ruby>
1050
+
1051
+ h5. submit_tag
1052
+
1053
+ Creates a submit button with the text provided as the caption.
1054
+
1055
+ <ruby>
1056
+ submit_tag "Publish this post"
1057
+ # => <input name="commit" type="submit" value="Publish this post" />
1058
+ </ruby>
1059
+
1060
+ h5. text_area_tag
1061
+
1062
+ Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.
1063
+
1064
+ <ruby>
1065
+ text_area_tag 'post'
1066
+ # => <textarea id="post" name="post"></textarea>
1067
+ </ruby>
1068
+
1069
+ h5. text_field_tag
1070
+
1071
+ Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query.
1072
+
1073
+ <ruby>
1074
+ text_field_tag 'name'
1075
+ # => <input id="name" name="name" type="text" />
1076
+ </ruby>
1077
+
1078
+ h4. JavaScriptHelper
1079
+
1080
+ Provides functionality for working with JavaScript in your views.
1081
+
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 +<%= javascript_include_tag :defaults, :cache => true %>+ is in the HEAD section of your page. This function will include the necessary JavaScript files Rails generated in the public/javascripts directory.
1083
+
1084
+ h5. button_to_function
1085
+
1086
+ Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
1087
+
1088
+ <ruby>
1089
+ button_to_function "Greeting", "alert('Hello world!')"
1090
+ button_to_function "Delete", "if (confirm('Really?')) do_delete()"
1091
+ button_to_function "Details" do |page|
1092
+ page[:details].visual_effect :toggle_slide
1093
+ end
1094
+ </ruby>
1095
+
1096
+ h5. define_javascript_functions
1097
+
1098
+ Includes the Action Pack JavaScript libraries inside a single +script+ tag.
1099
+
1100
+ h5. escape_javascript
1101
+
1102
+ Escape carrier returns and single and double quotes for JavaScript segments.
1103
+
1104
+ h5. javascript_tag
1105
+
1106
+ Returns a JavaScript tag wrapping the provided code.
1107
+
1108
+ <ruby>
1109
+ javascript_tag "alert('All is good')"
1110
+ </ruby>
1111
+
1112
+ <html>
1113
+ <script type="text/javascript">
1114
+ //<![CDATA[
1115
+ alert('All is good')
1116
+ //]]>
1117
+ </script>
1118
+ </html>
1119
+
1120
+ h5. link_to_function
1121
+
1122
+ Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.
1123
+
1124
+ <ruby>
1125
+ link_to_function "Greeting", "alert('Hello world!')"
1126
+ # => <a onclick="alert('Hello world!'); return false;" href="#">Greeting</a>
1127
+ </ruby>
1128
+
1129
+ h4. NumberHelper
1130
+
1131
+ Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.
1132
+
1133
+ h5. number_to_currency
1134
+
1135
+ Formats a number into a currency string (e.g., $13.65).
1136
+
1137
+ <ruby>
1138
+ number_to_currency(1234567890.50) # => $1,234,567,890.50
1139
+ </ruby>
1140
+
1141
+ h5. number_to_human_size
1142
+
1143
+ Formats the bytes in size into a more understandable representation; useful for reporting file sizes to users.
1144
+
1145
+ <ruby>
1146
+ number_to_human_size(1234) # => 1.2 KB
1147
+ number_to_human_size(1234567) # => 1.2 MB
1148
+ </ruby>
1149
+
1150
+ h5. number_to_percentage
1151
+
1152
+ Formats a number as a percentage string.
1153
+
1154
+ <ruby>
1155
+ number_to_percentage(100, :precision => 0) # => 100%
1156
+ </ruby>
1157
+
1158
+ h5. number_to_phone
1159
+
1160
+ Formats a number into a US phone number.
1161
+
1162
+ <ruby>
1163
+ number_to_phone(1235551234) # => 123-555-1234
1164
+ </ruby>
1165
+
1166
+ h5. number_with_delimiter
1167
+
1168
+ Formats a number with grouped thousands using a delimiter.
1169
+
1170
+ <ruby>
1171
+ number_with_delimiter(12345678) # => 12,345,678
1172
+ </ruby>
1173
+
1174
+ h5. number_with_precision
1175
+
1176
+ Formats a number with the specified level of +precision+, which defaults to 3.
1177
+
1178
+ <ruby>
1179
+ number_with_precision(111.2345) # => 111.235
1180
+ number_with_precision(111.2345, 2) # => 111.23
1181
+ </ruby>
1182
+
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
+ h5. evaluate_remote_response
1194
+
1195
+ 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.
1196
+
1197
+ h5. form_remote_tag
1198
+
1199
+ Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it‘s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side.
1200
+
1201
+ For example, this:
1202
+
1203
+ <ruby>
1204
+ form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") }
1205
+ </ruby>
1206
+
1207
+ would generate the following:
1208
+
1209
+ <html>
1210
+ <form action="/some/place" method="post" onsubmit="new Ajax.Request('',
1211
+ {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
1212
+ </html>
1213
+
1214
+ h5. link_to_remote
1215
+
1216
+ Returns a link to a remote action that's called in the background using XMLHttpRequest. You can generate a link that uses AJAX in the general case, while degrading gracefully to plain link behavior in the absence of JavaScript. For example:
1217
+
1218
+ <ruby>
1219
+ link_to_remote "Delete this post",
1220
+ { :update => "posts", :url => { :action => "destroy", :id => post.id } },
1221
+ :href => url_for(:action => "destroy", :id => post.id)
1222
+ </ruby>
1223
+
1224
+ h5. observe_field
1225
+
1226
+ Observes the field specified and calls a callback when its contents have changed.
1227
+
1228
+ <ruby>
1229
+ observe_field("my_field", :function => "alert('Field changed')")
1230
+ </ruby>
1231
+
1232
+ h5. observe_form
1233
+
1234
+ Observes the form specified and calls a callback when its contents have changed. The options for observe_form are the same as the options for observe_field.
1235
+
1236
+ <ruby>
1237
+ observe_field("my_form", :function => "alert('Form changed')")
1238
+ </ruby>
1239
+
1240
+ h5. periodically_call_remote
1241
+
1242
+ Periodically calls the specified url as often as specified. Usually used to update a specified div with the results of the remote call. The following example will call update every 20 seconds and update the news_block div:
1243
+
1244
+ <ruby>
1245
+ periodically_call_remote(:url => 'update', :frequency => '20', :update => 'news_block')
1246
+ # => PeriodicalExecuter(function() {new Ajax.Updater('news_block', 'update', {asynchronous:true, evalScripts:true})}, 20)
1247
+ </ruby>
1248
+
1249
+ h5. remote_form_for
1250
+
1251
+ Creates a form that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement and a scope around a specific resource that is used as a base for questioning about values for the fields.
1252
+
1253
+ <ruby>
1254
+ <% remote_form_for(@post) do |f| %>
1255
+ ...
1256
+ <% end %>
1257
+ </ruby>
1258
+
1259
+ h5. remote_function
1260
+
1261
+ Returns the JavaScript needed for a remote function. Takes the same arguments as +link_to_remote+.
1262
+
1263
+ <ruby>
1264
+ <select id="options" onchange="<%= remote_function(:update => "options", :url => { :action => :update_options }) %>">
1265
+ <option value="0">Hello</option>
1266
+ <option value="1">World</option>
1267
+ </select>
1268
+ # => <select id="options" onchange="new Ajax.Updater('options', '/testing/update_options', {asynchronous:true, evalScripts:true})">
1269
+ </ruby>
1270
+
1271
+ h5. submit_to_remote
1272
+
1273
+ Returns a button input tag that will submit form using XMLHttpRequest in the background instead of a regular POST request that reloads the page.
1274
+
1275
+ For example, the following:
1276
+
1277
+ <ruby>
1278
+ submit_to_remote 'create_btn', 'Create', :url => { :action => 'create' }
1279
+ </ruby>
1280
+
1281
+ would generate:
1282
+
1283
+ <html>
1284
+ <input name="create_btn" onclick="new Ajax.Request('/testing/create',
1285
+ {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
1286
+ return false;" type="button" value="Create" />
1287
+ </html>
1288
+
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. <<
1308
+
1309
+ Writes raw JavaScript to the page.
1310
+
1311
+ <ruby>
1312
+ page << "alert('JavaScript with Prototype.');"
1313
+ </ruby>
1314
+
1315
+ h5. []
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. 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
+ h3. Localized Views
1455
+
1456
+ Action View has the ability render different templates depending on the current locale.
1457
+
1458
+ For example, suppose you have a Posts controller with a show action. By default, calling this action will render +app/views/posts/show.html.erb+. But if you set +I18n.locale = :de+, then +app/views/posts/show.de.html.erb+ will be rendered instead. If the localized template isn't present, the undecorated version will be used. This means you're not required to provide localized views for all cases, but they will be preferred and used if available.
1459
+
1460
+ You can use the same technique to localize the rescue files in your public directory. For example, setting +I18n.locale = :de+ and creating +public/500.de.html+ and +public/404.de.html+ would allow you to have localized rescue pages.
1461
+
1462
+ Since Rails doesn't restrict the symbols that you use to set I18n.locale, you can leverage this system to display different content depending on anything you like. For example, suppose you have some "expert" users that should see different pages from "normal" users. You could add the following to +app/controllers/application.rb+:
1463
+
1464
+ <ruby>
1465
+ before_filter :set_expert_locale
1466
+
1467
+ def set_expert_locale
1468
+ I18n.locale = :expert if current_user.expert?
1469
+ end
1470
+ </ruby>
1471
+
1472
+ Then you could create special views like +app/views/posts/show.expert.html.erb+ that would only be displayed to expert users.
1473
+
1474
+ You can read more about the Rails Internationalization (I18n) API "here":i18n.html.
1475
+
1476
+ h3. Changelog
1477
+
1478
+ "Lighthouse Ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/71
1479
+
1480
+ * 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
1481
+ * April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs