openskies 0.0.5.2 → 0.0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (491) hide show
  1. data/CHANGELOG.md +0 -87
  2. data/bin/openskies +31 -5
  3. metadata +4 -593
  4. data/guides/assets/images/belongs_to.png +0 -0
  5. data/guides/assets/images/book_icon.gif +0 -0
  6. data/guides/assets/images/bullet.gif +0 -0
  7. data/guides/assets/images/challenge.png +0 -0
  8. data/guides/assets/images/chapters_icon.gif +0 -0
  9. data/guides/assets/images/check_bullet.gif +0 -0
  10. data/guides/assets/images/credits_pic_blank.gif +0 -0
  11. data/guides/assets/images/csrf.png +0 -0
  12. data/guides/assets/images/customized_error_messages.png +0 -0
  13. data/guides/assets/images/edge_badge.png +0 -0
  14. data/guides/assets/images/error_messages.png +0 -0
  15. data/guides/assets/images/feature_tile.gif +0 -0
  16. data/guides/assets/images/footer_tile.gif +0 -0
  17. data/guides/assets/images/fxn.png +0 -0
  18. data/guides/assets/images/grey_bullet.gif +0 -0
  19. data/guides/assets/images/habtm.png +0 -0
  20. data/guides/assets/images/has_many.png +0 -0
  21. data/guides/assets/images/has_many_through.png +0 -0
  22. data/guides/assets/images/has_one.png +0 -0
  23. data/guides/assets/images/has_one_through.png +0 -0
  24. data/guides/assets/images/header_backdrop.png +0 -0
  25. data/guides/assets/images/header_tile.gif +0 -0
  26. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  27. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  28. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  29. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  30. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  31. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  32. data/guides/assets/images/icons/README +0 -5
  33. data/guides/assets/images/icons/callouts/1.png +0 -0
  34. data/guides/assets/images/icons/callouts/10.png +0 -0
  35. data/guides/assets/images/icons/callouts/11.png +0 -0
  36. data/guides/assets/images/icons/callouts/12.png +0 -0
  37. data/guides/assets/images/icons/callouts/13.png +0 -0
  38. data/guides/assets/images/icons/callouts/14.png +0 -0
  39. data/guides/assets/images/icons/callouts/15.png +0 -0
  40. data/guides/assets/images/icons/callouts/2.png +0 -0
  41. data/guides/assets/images/icons/callouts/3.png +0 -0
  42. data/guides/assets/images/icons/callouts/4.png +0 -0
  43. data/guides/assets/images/icons/callouts/5.png +0 -0
  44. data/guides/assets/images/icons/callouts/6.png +0 -0
  45. data/guides/assets/images/icons/callouts/7.png +0 -0
  46. data/guides/assets/images/icons/callouts/8.png +0 -0
  47. data/guides/assets/images/icons/callouts/9.png +0 -0
  48. data/guides/assets/images/icons/caution.png +0 -0
  49. data/guides/assets/images/icons/example.png +0 -0
  50. data/guides/assets/images/icons/home.png +0 -0
  51. data/guides/assets/images/icons/important.png +0 -0
  52. data/guides/assets/images/icons/next.png +0 -0
  53. data/guides/assets/images/icons/note.png +0 -0
  54. data/guides/assets/images/icons/prev.png +0 -0
  55. data/guides/assets/images/icons/tip.png +0 -0
  56. data/guides/assets/images/icons/up.png +0 -0
  57. data/guides/assets/images/icons/warning.png +0 -0
  58. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  59. data/guides/assets/images/nav_arrow.gif +0 -0
  60. data/guides/assets/images/polymorphic.png +0 -0
  61. data/guides/assets/images/posts_index.png +0 -0
  62. data/guides/assets/images/radar.png +0 -0
  63. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  64. data/guides/assets/images/rails_guides_logo.gif +0 -0
  65. data/guides/assets/images/rails_logo_remix.gif +0 -0
  66. data/guides/assets/images/rails_welcome.png +0 -0
  67. data/guides/assets/images/session_fixation.png +0 -0
  68. data/guides/assets/images/tab_grey.gif +0 -0
  69. data/guides/assets/images/tab_info.gif +0 -0
  70. data/guides/assets/images/tab_note.gif +0 -0
  71. data/guides/assets/images/tab_red.gif +0 -0
  72. data/guides/assets/images/tab_yellow.gif +0 -0
  73. data/guides/assets/images/tab_yellow.png +0 -0
  74. data/guides/assets/images/validation_error_messages.png +0 -0
  75. data/guides/assets/images/vijaydev.jpg +0 -0
  76. data/guides/assets/javascripts/guides.js +0 -7
  77. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  78. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  79. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  80. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  81. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  82. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  83. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  84. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  85. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  86. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  87. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  88. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  89. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  90. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  91. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  102. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +0 -17
  103. data/guides/assets/stylesheets/fixes.css +0 -16
  104. data/guides/assets/stylesheets/kindle.css +0 -11
  105. data/guides/assets/stylesheets/main.css +0 -453
  106. data/guides/assets/stylesheets/print.css +0 -52
  107. data/guides/assets/stylesheets/reset.css +0 -43
  108. data/guides/assets/stylesheets/style.css +0 -13
  109. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +0 -226
  110. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  111. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  112. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  113. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  114. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  115. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  116. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  117. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  118. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  119. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  120. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  121. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  122. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  123. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  124. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  125. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  126. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  127. data/guides/code/getting_started/Gemfile +0 -38
  128. data/guides/code/getting_started/README.rdoc +0 -261
  129. data/guides/code/getting_started/Rakefile +0 -7
  130. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  131. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  132. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  133. data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +0 -3
  134. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  135. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  136. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  137. data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +0 -3
  138. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  139. data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +0 -56
  140. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -3
  141. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -16
  142. data/guides/code/getting_started/app/controllers/home_controller.rb +0 -5
  143. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -84
  144. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  145. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  146. data/guides/code/getting_started/app/helpers/home_helper.rb +0 -2
  147. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -5
  148. data/guides/code/getting_started/app/models/comment.rb +0 -3
  149. data/guides/code/getting_started/app/models/post.rb +0 -11
  150. data/guides/code/getting_started/app/models/tag.rb +0 -3
  151. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  152. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  153. data/guides/code/getting_started/app/views/home/index.html.erb +0 -2
  154. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  155. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -32
  156. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -6
  157. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -27
  158. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  159. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -31
  160. data/guides/code/getting_started/app/views/tags/_form.html.erb +0 -12
  161. data/guides/code/getting_started/config/application.rb +0 -59
  162. data/guides/code/getting_started/config/boot.rb +0 -6
  163. data/guides/code/getting_started/config/database.yml +0 -25
  164. data/guides/code/getting_started/config/environment.rb +0 -5
  165. data/guides/code/getting_started/config/environments/development.rb +0 -37
  166. data/guides/code/getting_started/config/environments/production.rb +0 -67
  167. data/guides/code/getting_started/config/environments/test.rb +0 -37
  168. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  169. data/guides/code/getting_started/config/initializers/inflections.rb +0 -15
  170. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  171. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -7
  172. data/guides/code/getting_started/config/initializers/session_store.rb +0 -8
  173. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  174. data/guides/code/getting_started/config/locales/en.yml +0 -5
  175. data/guides/code/getting_started/config/routes.rb +0 -64
  176. data/guides/code/getting_started/config.ru +0 -4
  177. data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +0 -11
  178. data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +0 -12
  179. data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +0 -11
  180. data/guides/code/getting_started/db/schema.rb +0 -43
  181. data/guides/code/getting_started/db/seeds.rb +0 -7
  182. data/guides/code/getting_started/doc/README_FOR_APP +0 -2
  183. data/guides/code/getting_started/public/404.html +0 -26
  184. data/guides/code/getting_started/public/422.html +0 -26
  185. data/guides/code/getting_started/public/500.html +0 -25
  186. data/guides/code/getting_started/public/favicon.ico +0 -0
  187. data/guides/code/getting_started/public/robots.txt +0 -5
  188. data/guides/code/getting_started/script/rails +0 -6
  189. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  190. data/guides/code/getting_started/test/fixtures/posts.yml +0 -11
  191. data/guides/code/getting_started/test/fixtures/tags.yml +0 -9
  192. data/guides/code/getting_started/test/functional/comments_controller_test.rb +0 -7
  193. data/guides/code/getting_started/test/functional/home_controller_test.rb +0 -9
  194. data/guides/code/getting_started/test/functional/posts_controller_test.rb +0 -49
  195. data/guides/code/getting_started/test/performance/browsing_test.rb +0 -12
  196. data/guides/code/getting_started/test/test_helper.rb +0 -13
  197. data/guides/code/getting_started/test/unit/comment_test.rb +0 -7
  198. data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +0 -4
  199. data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +0 -4
  200. data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +0 -4
  201. data/guides/code/getting_started/test/unit/post_test.rb +0 -7
  202. data/guides/code/getting_started/test/unit/tag_test.rb +0 -7
  203. data/guides/rails_guides/generator.rb +0 -310
  204. data/guides/rails_guides/helpers.rb +0 -45
  205. data/guides/rails_guides/indexer.rb +0 -69
  206. data/guides/rails_guides/levenshtein.rb +0 -31
  207. data/guides/rails_guides/textile_extensions.rb +0 -63
  208. data/guides/rails_guides.rb +0 -50
  209. data/guides/source/2_2_release_notes.textile +0 -422
  210. data/guides/source/2_3_release_notes.textile +0 -610
  211. data/guides/source/3_0_release_notes.textile +0 -595
  212. data/guides/source/3_1_release_notes.textile +0 -553
  213. data/guides/source/3_2_release_notes.textile +0 -540
  214. data/guides/source/_license.html.erb +0 -2
  215. data/guides/source/_welcome.html.erb +0 -19
  216. data/guides/source/action_controller_overview.textile +0 -820
  217. data/guides/source/action_mailer_basics.textile +0 -516
  218. data/guides/source/action_view_overview.textile +0 -1497
  219. data/guides/source/active_model_basics.textile +0 -205
  220. data/guides/source/active_record_basics.textile +0 -218
  221. data/guides/source/active_record_querying.textile +0 -1433
  222. data/guides/source/active_record_validations_callbacks.textile +0 -1283
  223. data/guides/source/active_resource_basics.textile +0 -120
  224. data/guides/source/active_support_core_extensions.textile +0 -3713
  225. data/guides/source/ajax_on_rails.textile +0 -267
  226. data/guides/source/api_documentation_guidelines.textile +0 -185
  227. data/guides/source/asset_pipeline.textile +0 -707
  228. data/guides/source/association_basics.textile +0 -1959
  229. data/guides/source/caching_with_rails.textile +0 -437
  230. data/guides/source/command_line.textile +0 -574
  231. data/guides/source/configuring.textile +0 -641
  232. data/guides/source/contributing_to_ruby_on_rails.textile +0 -448
  233. data/guides/source/credits.html.erb +0 -72
  234. data/guides/source/debugging_rails_applications.textile +0 -714
  235. data/guides/source/documents.yaml +0 -157
  236. data/guides/source/engines.textile +0 -618
  237. data/guides/source/form_helpers.textile +0 -798
  238. data/guides/source/generators.textile +0 -621
  239. data/guides/source/getting_started.textile +0 -1929
  240. data/guides/source/i18n.textile +0 -931
  241. data/guides/source/index.html.erb +0 -30
  242. data/guides/source/initialization.textile +0 -1116
  243. data/guides/source/kindle/KINDLE.md +0 -26
  244. data/guides/source/kindle/copyright.html.erb +0 -1
  245. data/guides/source/kindle/layout.html.erb +0 -27
  246. data/guides/source/kindle/rails_guides.opf.erb +0 -52
  247. data/guides/source/kindle/toc.html.erb +0 -24
  248. data/guides/source/kindle/toc.ncx.erb +0 -64
  249. data/guides/source/kindle/welcome.html.erb +0 -5
  250. data/guides/source/layout.html.erb +0 -124
  251. data/guides/source/layouts_and_rendering.textile +0 -1237
  252. data/guides/source/migrations.textile +0 -900
  253. data/guides/source/nested_model_forms.textile +0 -222
  254. data/guides/source/performance_testing.textile +0 -597
  255. data/guides/source/plugins.textile +0 -464
  256. data/guides/source/rails_application_templates.textile +0 -240
  257. data/guides/source/rails_on_rack.textile +0 -236
  258. data/guides/source/routing.textile +0 -885
  259. data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -79
  260. data/guides/source/security.textile +0 -1004
  261. data/guides/source/testing.textile +0 -947
  262. data/guides/w3c_validator.rb +0 -91
  263. data/lib/rails/all.rb +0 -15
  264. data/lib/rails/application/bootstrap.rb +0 -73
  265. data/lib/rails/application/configuration.rb +0 -151
  266. data/lib/rails/application/finisher.rb +0 -98
  267. data/lib/rails/application/railties.rb +0 -13
  268. data/lib/rails/application/route_inspector.rb +0 -84
  269. data/lib/rails/application/routes_reloader.rb +0 -56
  270. data/lib/rails/application.rb +0 -320
  271. data/lib/rails/backtrace_cleaner.rb +0 -42
  272. data/lib/rails/cli.rb +0 -16
  273. data/lib/rails/code_statistics.rb +0 -118
  274. data/lib/rails/commands/application.rb +0 -36
  275. data/lib/rails/commands/benchmarker.rb +0 -34
  276. data/lib/rails/commands/console.rb +0 -55
  277. data/lib/rails/commands/dbconsole.rb +0 -123
  278. data/lib/rails/commands/destroy.rb +0 -10
  279. data/lib/rails/commands/generate.rb +0 -12
  280. data/lib/rails/commands/plugin.rb +0 -544
  281. data/lib/rails/commands/plugin_new.rb +0 -11
  282. data/lib/rails/commands/profiler.rb +0 -32
  283. data/lib/rails/commands/runner.rb +0 -54
  284. data/lib/rails/commands/server.rb +0 -100
  285. data/lib/rails/commands/update.rb +0 -9
  286. data/lib/rails/commands.rb +0 -104
  287. data/lib/rails/configuration.rb +0 -89
  288. data/lib/rails/console/app.rb +0 -36
  289. data/lib/rails/console/helpers.rb +0 -11
  290. data/lib/rails/engine/commands.rb +0 -43
  291. data/lib/rails/engine/configuration.rb +0 -84
  292. data/lib/rails/engine/railties.rb +0 -33
  293. data/lib/rails/engine.rb +0 -657
  294. data/lib/rails/generators/actions.rb +0 -325
  295. data/lib/rails/generators/active_model.rb +0 -78
  296. data/lib/rails/generators/app_base.rb +0 -266
  297. data/lib/rails/generators/base.rb +0 -390
  298. data/lib/rails/generators/css/assets/assets_generator.rb +0 -13
  299. data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
  300. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -16
  301. data/lib/rails/generators/erb/controller/controller_generator.rb +0 -20
  302. data/lib/rails/generators/erb/controller/templates/view.html.erb +0 -2
  303. data/lib/rails/generators/erb/mailer/mailer_generator.rb +0 -13
  304. data/lib/rails/generators/erb/mailer/templates/view.text.erb +0 -3
  305. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -29
  306. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +0 -23
  307. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +0 -6
  308. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +0 -27
  309. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +0 -5
  310. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +0 -12
  311. data/lib/rails/generators/erb.rb +0 -21
  312. data/lib/rails/generators/generated_attribute.rb +0 -107
  313. data/lib/rails/generators/js/assets/assets_generator.rb +0 -13
  314. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  315. data/lib/rails/generators/migration.rb +0 -68
  316. data/lib/rails/generators/named_base.rb +0 -202
  317. data/lib/rails/generators/rails/app/USAGE +0 -15
  318. data/lib/rails/generators/rails/app/app_generator.rb +0 -312
  319. data/lib/rails/generators/rails/app/templates/Gemfile +0 -21
  320. data/lib/rails/generators/rails/app/templates/README +0 -261
  321. data/lib/rails/generators/rails/app/templates/Rakefile +0 -7
  322. data/lib/rails/generators/rails/app/templates/app/assets/images/rails.png +0 -0
  323. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -17
  324. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +0 -13
  325. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +0 -3
  326. data/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb +0 -2
  327. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  328. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  329. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +0 -14
  330. data/lib/rails/generators/rails/app/templates/config/application.rb +0 -68
  331. data/lib/rails/generators/rails/app/templates/config/boot.rb +0 -6
  332. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +0 -31
  333. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +0 -86
  334. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
  335. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +0 -33
  336. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +0 -43
  337. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +0 -20
  338. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +0 -54
  339. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +0 -39
  340. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +0 -55
  341. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +0 -25
  342. data/lib/rails/generators/rails/app/templates/config/environment.rb +0 -5
  343. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +0 -41
  344. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +0 -73
  345. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +0 -39
  346. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +0 -7
  347. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +0 -15
  348. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb +0 -5
  349. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +0 -7
  350. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -8
  351. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
  352. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +0 -5
  353. data/lib/rails/generators/rails/app/templates/config/routes.rb +0 -58
  354. data/lib/rails/generators/rails/app/templates/config.ru +0 -4
  355. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +0 -7
  356. data/lib/rails/generators/rails/app/templates/doc/README_FOR_APP +0 -2
  357. data/lib/rails/generators/rails/app/templates/gitignore +0 -15
  358. data/lib/rails/generators/rails/app/templates/public/404.html +0 -26
  359. data/lib/rails/generators/rails/app/templates/public/422.html +0 -26
  360. data/lib/rails/generators/rails/app/templates/public/500.html +0 -25
  361. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -5
  362. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  363. data/lib/rails/generators/rails/app/templates/script/openskies +0 -5
  364. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  365. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  366. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  367. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +0 -12
  368. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -15
  369. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  370. data/lib/rails/generators/rails/assets/USAGE +0 -20
  371. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -25
  372. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
  373. data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
  374. data/lib/rails/generators/rails/controller/USAGE +0 -18
  375. data/lib/rails/generators/rails/controller/controller_generator.rb +0 -20
  376. data/lib/rails/generators/rails/controller/templates/controller.rb +0 -13
  377. data/lib/rails/generators/rails/generator/USAGE +0 -12
  378. data/lib/rails/generators/rails/generator/generator_generator.rb +0 -25
  379. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +0 -3
  380. data/lib/rails/generators/rails/generator/templates/USAGE.tt +0 -8
  381. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  382. data/lib/rails/generators/rails/helper/USAGE +0 -17
  383. data/lib/rails/generators/rails/helper/helper_generator.rb +0 -13
  384. data/lib/rails/generators/rails/helper/templates/helper.rb +0 -4
  385. data/lib/rails/generators/rails/integration_test/USAGE +0 -10
  386. data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +0 -7
  387. data/lib/rails/generators/rails/migration/USAGE +0 -29
  388. data/lib/rails/generators/rails/migration/migration_generator.rb +0 -8
  389. data/lib/rails/generators/rails/model/USAGE +0 -45
  390. data/lib/rails/generators/rails/model/model_generator.rb +0 -8
  391. data/lib/rails/generators/rails/observer/USAGE +0 -12
  392. data/lib/rails/generators/rails/observer/observer_generator.rb +0 -7
  393. data/lib/rails/generators/rails/performance_test/USAGE +0 -10
  394. data/lib/rails/generators/rails/performance_test/performance_test_generator.rb +0 -7
  395. data/lib/rails/generators/rails/plugin_new/USAGE +0 -10
  396. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +0 -318
  397. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +0 -29
  398. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +0 -23
  399. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +0 -20
  400. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +0 -3
  401. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +0 -31
  402. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +0 -4
  403. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
  404. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  405. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  406. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
  407. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +0 -6
  408. data/lib/rails/generators/rails/plugin_new/templates/gitignore +0 -7
  409. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +0 -7
  410. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb +0 -3
  411. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +0 -6
  412. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +0 -4
  413. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +0 -18
  414. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +0 -10
  415. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +0 -4
  416. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +0 -7
  417. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +0 -7
  418. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +0 -12
  419. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +0 -15
  420. data/lib/rails/generators/rails/resource/USAGE +0 -23
  421. data/lib/rails/generators/rails/resource/resource_generator.rb +0 -20
  422. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -50
  423. data/lib/rails/generators/rails/scaffold/USAGE +0 -35
  424. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +0 -23
  425. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -56
  426. data/lib/rails/generators/rails/scaffold_controller/USAGE +0 -19
  427. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -25
  428. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +0 -89
  429. data/lib/rails/generators/rails/session_migration/USAGE +0 -8
  430. data/lib/rails/generators/rails/session_migration/session_migration_generator.rb +0 -8
  431. data/lib/rails/generators/rails/task/USAGE +0 -9
  432. data/lib/rails/generators/rails/task/task_generator.rb +0 -12
  433. data/lib/rails/generators/rails/task/templates/task.rb +0 -8
  434. data/lib/rails/generators/resource_helpers.rb +0 -80
  435. data/lib/rails/generators/test_case.rb +0 -247
  436. data/lib/rails/generators/test_unit/controller/controller_generator.rb +0 -15
  437. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +0 -19
  438. data/lib/rails/generators/test_unit/helper/helper_generator.rb +0 -13
  439. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +0 -6
  440. data/lib/rails/generators/test_unit/integration/integration_generator.rb +0 -13
  441. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -7
  442. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +0 -14
  443. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +0 -21
  444. data/lib/rails/generators/test_unit/model/model_generator.rb +0 -24
  445. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +0 -23
  446. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +0 -9
  447. data/lib/rails/generators/test_unit/observer/observer_generator.rb +0 -13
  448. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +0 -9
  449. data/lib/rails/generators/test_unit/performance/performance_generator.rb +0 -13
  450. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +0 -12
  451. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +0 -13
  452. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +0 -7
  453. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +0 -3
  454. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +0 -38
  455. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +0 -51
  456. data/lib/rails/generators/test_unit.rb +0 -8
  457. data/lib/rails/generators.rb +0 -339
  458. data/lib/rails/info.rb +0 -116
  459. data/lib/rails/info_controller.rb +0 -15
  460. data/lib/rails/initializable.rb +0 -89
  461. data/lib/rails/paths.rb +0 -211
  462. data/lib/rails/performance_test_help.rb +0 -3
  463. data/lib/rails/plugin.rb +0 -92
  464. data/lib/rails/rack/debugger.rb +0 -24
  465. data/lib/rails/rack/log_tailer.rb +0 -34
  466. data/lib/rails/rack/logger.rb +0 -60
  467. data/lib/rails/rack.rb +0 -7
  468. data/lib/rails/railtie/configurable.rb +0 -35
  469. data/lib/rails/railtie/configuration.rb +0 -90
  470. data/lib/rails/railtie.rb +0 -202
  471. data/lib/rails/ruby_version_check.rb +0 -23
  472. data/lib/rails/rubyprof_ext.rb +0 -35
  473. data/lib/rails/script_rails_loader.rb +0 -29
  474. data/lib/rails/source_annotation_extractor.rb +0 -104
  475. data/lib/rails/tasks/annotations.rake +0 -20
  476. data/lib/rails/tasks/documentation.rake +0 -155
  477. data/lib/rails/tasks/engine.rake +0 -72
  478. data/lib/rails/tasks/framework.rake +0 -76
  479. data/lib/rails/tasks/log.rake +0 -9
  480. data/lib/rails/tasks/middleware.rake +0 -7
  481. data/lib/rails/tasks/misc.rake +0 -67
  482. data/lib/rails/tasks/routes.rake +0 -9
  483. data/lib/rails/tasks/statistics.rake +0 -16
  484. data/lib/rails/tasks/tmp.rake +0 -37
  485. data/lib/rails/tasks.rb +0 -16
  486. data/lib/rails/test_help.rb +0 -56
  487. data/lib/rails/test_unit/railtie.rb +0 -15
  488. data/lib/rails/test_unit/sub_test_task.rb +0 -8
  489. data/lib/rails/test_unit/testing.rake +0 -146
  490. data/lib/rails.rb +0 -121
  491. data/lib/version.rb +0 -16
@@ -1,1237 +0,0 @@
1
- h2. Layouts and Rendering in Rails
2
-
3
- This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to:
4
-
5
- * Use the various rendering methods built into Rails
6
- * Create layouts with multiple content sections
7
- * Use partials to DRY up your views
8
- * Use nested layouts (sub-templates)
9
-
10
- endprologue.
11
-
12
- h3. Overview: How the Pieces Fit Together
13
-
14
- This guide focuses on the interaction between Controller and View in the Model-View-Controller triangle. As you know, the Controller is responsible for orchestrating the whole process of handling a request in Rails, though it normally hands off any heavy code to the Model. But then, when it's time to send a response back to the user, the Controller hands things off to the View. It's that handoff that is the subject of this guide.
15
-
16
- In broad strokes, this involves deciding what should be sent as the response and calling an appropriate method to create that response. If the response is a full-blown view, Rails also does some extra work to wrap the view in a layout and possibly to pull in partial views. You'll see all of those paths later in this guide.
17
-
18
- h3. Creating Responses
19
-
20
- From the controller's point of view, there are three ways to create an HTTP response:
21
-
22
- * Call +render+ to create a full response to send back to the browser
23
- * Call +redirect_to+ to send an HTTP redirect status code to the browser
24
- * Call +head+ to create a response consisting solely of HTTP headers to send back to the browser
25
-
26
- I'll cover each of these methods in turn. But first, a few words about the very easiest thing that the controller can do to create a response: nothing at all.
27
-
28
- h4. Rendering by Default: Convention Over Configuration in Action
29
-
30
- You've heard that Rails promotes "convention over configuration". Default rendering is an excellent example of this. By default, controllers in Rails automatically render views with names that correspond to valid routes. For example, if you have this code in your +BooksController+ class:
31
-
32
- <ruby>
33
- class BooksController < ApplicationController
34
- end
35
- </ruby>
36
-
37
- And the following in your routes file:
38
-
39
- <ruby>
40
- resources :books
41
- </ruby>
42
-
43
- And you have a view file +app/views/books/index.html.erb+:
44
-
45
- <ruby>
46
- <h1>Books are coming soon!</h1>
47
- </ruby>
48
-
49
- Rails will automatically render +app/views/books/index.html.erb+ when you navigate to +/books+ and you will see "Books are coming soon!" on your screen.
50
-
51
- However a coming soon screen is only minimally useful, so you will soon create your +Book+ model and add the index action to +BooksController+:
52
-
53
- <ruby>
54
- class BooksController < ApplicationController
55
- def index
56
- @books = Book.all
57
- end
58
- end
59
- </ruby>
60
-
61
- Note that we don't have explicit render at the end of the index action in accordance with "convention over configuration" principle. The rule is that if you do not explicitly render something at the end of a controller action, Rails will automatically look for the +action_name.html.erb+ template in the controller's view path and render it. So in this case, Rails will render the +app/views/books/index.html.erb+ file.
62
-
63
- If we want to display the properties of all the books in our view, we can do so with an ERB template like this:
64
-
65
- <ruby>
66
- <h1>Listing Books</h1>
67
-
68
- <table>
69
- <tr>
70
- <th>Title</th>
71
- <th>Summary</th>
72
- <th></th>
73
- <th></th>
74
- <th></th>
75
- </tr>
76
-
77
- <% @books.each do |book| %>
78
- <tr>
79
- <td><%= book.title %></td>
80
- <td><%= book.content %></td>
81
- <td><%= link_to 'Show', book %></td>
82
- <td><%= link_to 'Edit', edit_book_path(book) %></td>
83
- <td><%= link_to 'Remove', book, :confirm => 'Are you sure?', :method => :delete %></td>
84
- </tr>
85
- <% end %>
86
- </table>
87
-
88
- <br />
89
-
90
- <%= link_to 'New book', new_book_path %>
91
- </ruby>
92
-
93
- NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. Beginning with Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), and +.builder+ for Builder (XML generator).
94
-
95
- h4. Using +render+
96
-
97
- In most cases, the +ActionController::Base#render+ method does the heavy lifting of rendering your application's content for use by a browser. There are a variety of ways to customize the behaviour of +render+. You can render the default view for a Rails template, or a specific template, or a file, or inline code, or nothing at all. You can render text, JSON, or XML. You can specify the content type or HTTP status of the rendered response as well.
98
-
99
- TIP: If you want to see the exact results of a call to +render+ without needing to inspect it in a browser, you can call +render_to_string+. This method takes exactly the same options as +render+, but it returns a string instead of sending a response back to the browser.
100
-
101
- h5. Rendering Nothing
102
-
103
- Perhaps the simplest thing you can do with +render+ is to render nothing at all:
104
-
105
- <ruby>
106
- render :nothing => true
107
- </ruby>
108
-
109
- If you look at the response for this using cURL, you will see the following:
110
-
111
- <shell>
112
- $ curl -i 127.0.0.1:3000/books
113
- HTTP/1.1 200 OK
114
- Connection: close
115
- Date: Sun, 24 Jan 2010 09:25:18 GMT
116
- Transfer-Encoding: chunked
117
- Content-Type: */*; charset=utf-8
118
- X-Runtime: 0.014297
119
- Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
120
- Cache-Control: no-cache
121
-
122
-
123
- $
124
- </shell>
125
-
126
- We see there is an empty response (no data after the +Cache-Control+ line), but the request was successful because Rails has set the response to 200 OK. You can set the +:status+ option on render to change this response. Rendering nothing can be useful for AJAX requests where all you want to send back to the browser is an acknowledgment that the request was completed.
127
-
128
- TIP: You should probably be using the +head+ method, discussed later in this guide, instead of +render :nothing+. This provides additional flexibility and makes it explicit that you're only generating HTTP headers.
129
-
130
- h5. Rendering an Action's View
131
-
132
- If you want to render the view that corresponds to a different action within the same template, you can use +render+ with the name of the view:
133
-
134
- <ruby>
135
- def update
136
- @book = Book.find(params[:id])
137
- if @book.update_attributes(params[:book])
138
- redirect_to(@book)
139
- else
140
- render "edit"
141
- end
142
- end
143
- </ruby>
144
-
145
- If the call to +update_attributes+ fails, calling the +update+ action in this controller will render the +edit.html.erb+ template belonging to the same controller.
146
-
147
- If you prefer, you can use a symbol instead of a string to specify the action to render:
148
-
149
- <ruby>
150
- def update
151
- @book = Book.find(params[:id])
152
- if @book.update_attributes(params[:book])
153
- redirect_to(@book)
154
- else
155
- render :edit
156
- end
157
- end
158
- </ruby>
159
-
160
- To be explicit, you can use +render+ with the +:action+ option (though this is no longer necessary in Rails 3.0):
161
-
162
- <ruby>
163
- def update
164
- @book = Book.find(params[:id])
165
- if @book.update_attributes(params[:book])
166
- redirect_to(@book)
167
- else
168
- render :action => "edit"
169
- end
170
- end
171
- </ruby>
172
-
173
- WARNING: Using +render+ with +:action+ is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does _not_ run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling +render+.
174
-
175
- h5. Rendering an Action's Template from Another Controller
176
-
177
- What if you want to render a template from an entirely different controller from the one that contains the action code? You can also do that with +render+, which accepts the full path (relative to +app/views+) of the template to render. For example, if you're running code in an +AdminProductsController+ that lives in +app/controllers/admin+, you can render the results of an action to a template in +app/views/products+ this way:
178
-
179
- <ruby>
180
- render 'products/show'
181
- </ruby>
182
-
183
- Rails knows that this view belongs to a different controller because of the embedded slash character in the string. If you want to be explicit, you can use the +:template+ option (which was required on Rails 2.2 and earlier):
184
-
185
- <ruby>
186
- render :template => 'products/show'
187
- </ruby>
188
-
189
- h5. Rendering an Arbitrary File
190
-
191
- The +render+ method can also use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications):
192
-
193
- <ruby>
194
- render "/u/apps/warehouse_app/current/app/views/products/show"
195
- </ruby>
196
-
197
- Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the +:file+ option (which was required on Rails 2.2 and earlier):
198
-
199
- <ruby>
200
- render :file =>
201
- "/u/apps/warehouse_app/current/app/views/products/show"
202
- </ruby>
203
-
204
- The +:file+ option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content.
205
-
206
- NOTE: By default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the +:layout => true+ option.
207
-
208
- TIP: If you're running Rails on Microsoft Windows, you should use the +:file+ option to render a file, because Windows filenames do not have the same format as Unix filenames.
209
-
210
- h5. Wrapping it up
211
-
212
- The above three ways of rendering (rendering another template within the controller, rendering a template within another controller and rendering an arbitrary file on the file system) are actually variants of the same action.
213
-
214
- In fact, in the BooksController class, inside of the update action where we want to render the edit template if the book does not update successfully, all of the following render calls would all render the +edit.html.erb+ template in the +views/books+ directory:
215
-
216
- <ruby>
217
- render :edit
218
- render :action => :edit
219
- render 'edit'
220
- render 'edit.html.erb'
221
- render :action => 'edit'
222
- render :action => 'edit.html.erb'
223
- render 'books/edit'
224
- render 'books/edit.html.erb'
225
- render :template => 'books/edit'
226
- render :template => 'books/edit.html.erb'
227
- render '/path/to/rails/app/views/books/edit'
228
- render '/path/to/rails/app/views/books/edit.html.erb'
229
- render :file => '/path/to/rails/app/views/books/edit'
230
- render :file => '/path/to/rails/app/views/books/edit.html.erb'
231
- </ruby>
232
-
233
- Which one you use is really a matter of style and convention, but the rule of thumb is to use the simplest one that makes sense for the code you are writing.
234
-
235
- h5. Using +render+ with +:inline+
236
-
237
- The +render+ method can do without a view completely, if you're willing to use the +:inline+ option to supply ERB as part of the method call. This is perfectly valid:
238
-
239
- <ruby>
240
- render :inline =>
241
- "<% products.each do |p| %><p><%= p.name %></p><% end %>"
242
- </ruby>
243
-
244
- WARNING: There is seldom any good reason to use this option. Mixing ERB into your controllers defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. Use a separate erb view instead.
245
-
246
- By default, inline rendering uses ERB. You can force it to use Builder instead with the +:type+ option:
247
-
248
- <ruby>
249
- render :inline =>
250
- "xml.p {'Horrid coding practice!'}", :type => :builder
251
- </ruby>
252
-
253
- h5. Rendering Text
254
-
255
- You can send plain text - with no markup at all - back to the browser by using the +:text+ option to +render+:
256
-
257
- <ruby>
258
- render :text => "OK"
259
- </ruby>
260
-
261
- TIP: Rendering pure text is most useful when you're responding to AJAX or web service requests that are expecting something other than proper HTML.
262
-
263
- NOTE: By default, if you use the +:text+ option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the +:layout => true+ option.
264
-
265
- h5. Rendering JSON
266
-
267
- JSON is a JavaScript data format used by many AJAX libraries. Rails has built-in support for converting objects to JSON and rendering that JSON back to the browser:
268
-
269
- <ruby>
270
- render :json => @product
271
- </ruby>
272
-
273
- TIP: You don't need to call +to_json+ on the object that you want to render. If you use the +:json+ option, +render+ will automatically call +to_json+ for you.
274
-
275
- h5. Rendering XML
276
-
277
- Rails also has built-in support for converting objects to XML and rendering that XML back to the caller:
278
-
279
- <ruby>
280
- render :xml => @product
281
- </ruby>
282
-
283
- TIP: You don't need to call +to_xml+ on the object that you want to render. If you use the +:xml+ option, +render+ will automatically call +to_xml+ for you.
284
-
285
- h5. Rendering Vanilla JavaScript
286
-
287
- Rails can render vanilla JavaScript:
288
-
289
- <ruby>
290
- render :js => "alert('Hello Rails');"
291
- </ruby>
292
-
293
- This will send the supplied string to the browser with a MIME type of +text/javascript+.
294
-
295
- h5. Options for +render+
296
-
297
- Calls to the +render+ method generally accept four options:
298
-
299
- * +:content_type+
300
- * +:layout+
301
- * +:status+
302
- * +:location+
303
-
304
- h6. The +:content_type+ Option
305
-
306
- By default, Rails will serve the results of a rendering operation with the MIME content-type of +text/html+ (or +application/json+ if you use the +:json+ option, or +application/xml+ for the +:xml+ option.). There are times when you might like to change this, and you can do so by setting the +:content_type+ option:
307
-
308
- <ruby>
309
- render :file => filename, :content_type => 'application/rss'
310
- </ruby>
311
-
312
- h6. The +:layout+ Option
313
-
314
- With most of the options to +render+, the rendered content is displayed as part of the current layout. You'll learn more about layouts and how to use them later in this guide.
315
-
316
- You can use the +:layout+ option to tell Rails to use a specific file as the layout for the current action:
317
-
318
- <ruby>
319
- render :layout => 'special_layout'
320
- </ruby>
321
-
322
- You can also tell Rails to render with no layout at all:
323
-
324
- <ruby>
325
- render :layout => false
326
- </ruby>
327
-
328
- h6. The +:status+ Option
329
-
330
- Rails will automatically generate a response with the correct HTTP status code (in most cases, this is +200 OK+). You can use the +:status+ option to change this:
331
-
332
- <ruby>
333
- render :status => 500
334
- render :status => :forbidden
335
- </ruby>
336
-
337
- Rails understands both numeric and symbolic status codes.
338
-
339
- h6. The +:location+ Option
340
-
341
- You can use the +:location+ option to set the HTTP +Location+ header:
342
-
343
- <ruby>
344
- render :xml => photo, :location => photo_url(photo)
345
- </ruby>
346
-
347
- h5. Finding Layouts
348
-
349
- To find the current layout, Rails first looks for a file in +app/views/layouts+ with the same base name as the controller. For example, rendering actions from the +PhotosController+ class will use +app/views/layouts/photos.html.erb+ (or +app/views/layouts/photos.builder+). If there is no such controller-specific layout, Rails will use +app/views/layouts/application.html.erb+ or +app/views/layouts/application.builder+. If there is no +.erb+ layout, Rails will use a +.builder+ layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.
350
-
351
- h6. Specifying Layouts for Controllers
352
-
353
- You can override the default layout conventions in your controllers by using the +layout+ declaration. For example:
354
-
355
- <ruby>
356
- class ProductsController < ApplicationController
357
- layout "inventory"
358
- #...
359
- end
360
- </ruby>
361
-
362
- With this declaration, all of the methods within +ProductsController+ will use +app/views/layouts/inventory.html.erb+ for their layout.
363
-
364
- To assign a specific layout for the entire application, use a +layout+ declaration in your +ApplicationController+ class:
365
-
366
- <ruby>
367
- class ApplicationController < ActionController::Base
368
- layout "main"
369
- #...
370
- end
371
- </ruby>
372
-
373
- With this declaration, all of the views in the entire application will use +app/views/layouts/main.html.erb+ for their layout.
374
-
375
- h6. Choosing Layouts at Runtime
376
-
377
- You can use a symbol to defer the choice of layout until a request is processed:
378
-
379
- <ruby>
380
- class ProductsController < ApplicationController
381
- layout :products_layout
382
-
383
- def show
384
- @product = Product.find(params[:id])
385
- end
386
-
387
- private
388
- def products_layout
389
- @current_user.special? ? "special" : "products"
390
- end
391
-
392
- end
393
- </ruby>
394
-
395
- Now, if the current user is a special user, they'll get a special layout when viewing a product.
396
-
397
- You can even use an inline method, such as a Proc, to determine the layout. For example, if you pass a Proc object, the block you give the Proc will be given the +controller+ instance, so the layout can be determined based on the current request:
398
-
399
- <ruby>
400
- class ProductsController < ApplicationController
401
- layout Proc.new { |controller| controller.request.xhr? ? 'popup' : 'application' }
402
- end
403
- </ruby>
404
-
405
- h6. Conditional Layouts
406
-
407
- Layouts specified at the controller level support the +:only+ and +:except+ options. These options take either a method name, or an array of method names, corresponding to method names within the controller:
408
-
409
- <ruby>
410
- class ProductsController < ApplicationController
411
- layout "product", :except => [:index, :rss]
412
- end
413
- </ruby>
414
-
415
- With this declaration, the +product+ layout would be used for everything but the +rss+ and +index+ methods.
416
-
417
- h6. Layout Inheritance
418
-
419
- Layout declarations cascade downward in the hierarchy, and more specific layout declarations always override more general ones. For example:
420
-
421
- * +application_controller.rb+
422
-
423
- <ruby>
424
- class ApplicationController < ActionController::Base
425
- layout "main"
426
- end
427
- </ruby>
428
-
429
- * +posts_controller.rb+
430
-
431
- <ruby>
432
- class PostsController < ApplicationController
433
- end
434
- </ruby>
435
-
436
- * +special_posts_controller.rb+
437
-
438
- <ruby>
439
- class SpecialPostsController < PostsController
440
- layout "special"
441
- end
442
- </ruby>
443
-
444
- * +old_posts_controller.rb+
445
-
446
- <ruby>
447
- class OldPostsController < SpecialPostsController
448
- layout false
449
-
450
- def show
451
- @post = Post.find(params[:id])
452
- end
453
-
454
- def index
455
- @old_posts = Post.older
456
- render :layout => "old"
457
- end
458
- # ...
459
- end
460
- </ruby>
461
-
462
- In this application:
463
-
464
- * In general, views will be rendered in the +main+ layout
465
- * +PostsController#index+ will use the +main+ layout
466
- * +SpecialPostsController#index+ will use the +special+ layout
467
- * +OldPostsController#show+ will use no layout at all
468
- * +OldPostsController#index+ will use the +old+ layout
469
-
470
- h5. Avoiding Double Render Errors
471
-
472
- Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it's relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that +render+ works.
473
-
474
- For example, here's some code that will trigger this error:
475
-
476
- <ruby>
477
- def show
478
- @book = Book.find(params[:id])
479
- if @book.special?
480
- render :action => "special_show"
481
- end
482
- render :action => "regular_show"
483
- end
484
- </ruby>
485
-
486
- If +@book.special?+ evaluates to +true+, Rails will start the rendering process to dump the +@book+ variable into the +special_show+ view. But this will _not_ stop the rest of the code in the +show+ action from running, and when Rails hits the end of the action, it will start to render the +regular_show+ view - and throw an error. The solution is simple: make sure that you have only one call to +render+ or +redirect+ in a single code path. One thing that can help is +and return+. Here's a patched version of the method:
487
-
488
- <ruby>
489
- def show
490
- @book = Book.find(params[:id])
491
- if @book.special?
492
- render :action => "special_show" and return
493
- end
494
- render :action => "regular_show"
495
- end
496
- </ruby>
497
-
498
- Make sure to use +and return+ instead of +&amp;&amp; return+ because +&amp;&amp; return+ will not work due to the operator precedence in the Ruby Language.
499
-
500
- Note that the implicit render done by ActionController detects if +render+ has been called, so the following will work without errors:
501
-
502
- <ruby>
503
- def show
504
- @book = Book.find(params[:id])
505
- if @book.special?
506
- render :action => "special_show"
507
- end
508
- end
509
- </ruby>
510
-
511
- This will render a book with +special?+ set with the +special_show+ template, while other books will render with the default +show+ template.
512
-
513
- h4. Using +redirect_to+
514
-
515
- Another way to handle returning responses to an HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:
516
-
517
- <ruby>
518
- redirect_to photos_url
519
- </ruby>
520
-
521
- You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. There's also a special redirect that sends the user back to the page they just came from:
522
-
523
- <ruby>
524
- redirect_to :back
525
- </ruby>
526
-
527
- h5. Getting a Different Redirect Status Code
528
-
529
- Rails uses HTTP status code 302, a temporary redirect, when you call +redirect_to+. If you'd like to use a different status code, perhaps 301, a permanent redirect, you can use the +:status+ option:
530
-
531
- <ruby>
532
- redirect_to photos_path, :status => 301
533
- </ruby>
534
-
535
- Just like the +:status+ option for +render+, +:status+ for +redirect_to+ accepts both numeric and symbolic header designations.
536
-
537
- h5. The Difference Between +render+ and +redirect_to+
538
-
539
- Sometimes inexperienced developers think of +redirect_to+ as a sort of +goto+ command, moving execution from one place to another in your Rails code. This is _not_ correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back an HTTP 302 status code.
540
-
541
- Consider these actions to see the difference:
542
-
543
- <ruby>
544
- def index
545
- @books = Book.all
546
- end
547
-
548
- def show
549
- @book = Book.find_by_id(params[:id])
550
- if @book.nil?
551
- render :action => "index"
552
- end
553
- end
554
- </ruby>
555
-
556
- With the code in this form, there will likely be a problem if the +@book+ variable is +nil+. Remember, a +render :action+ doesn't run any code in the target action, so nothing will set up the +@books+ variable that the +index+ view will probably require. One way to fix this is to redirect instead of rendering:
557
-
558
- <ruby>
559
- def index
560
- @books = Book.all
561
- end
562
-
563
- def show
564
- @book = Book.find_by_id(params[:id])
565
- if @book.nil?
566
- redirect_to :action => :index
567
- end
568
- end
569
- </ruby>
570
-
571
- With this code, the browser will make a fresh request for the index page, the code in the +index+ method will run, and all will be well.
572
-
573
- The only downside to this code is that it requires a round trip to the browser: the browser requested the show action with +/books/1+ and the controller finds that there are no books, so the controller sends out a 302 redirect response to the browser telling it to go to +/books/+, the browser complies and sends a new request back to the controller asking now for the +index+ action, the controller then gets all the books in the database and renders the index template, sending it back down to the browser which then shows it on your screen.
574
-
575
- While in a small application, this added latency might not be a problem, it is something to think about if response time is a concern. We can demonstrate one way to handle this with a contrived example:
576
-
577
- <ruby>
578
- def index
579
- @books = Book.all
580
- end
581
-
582
- def show
583
- @book = Book.find_by_id(params[:id])
584
- if @book.nil?
585
- @books = Book.all
586
- render "index", :alert => 'Your book was not found!'
587
- end
588
- end
589
- </ruby>
590
-
591
- This would detect that there are no books with the specified ID, populate the +@books+ instance variable with all the books in the model, and then directly render the +index.html.erb+ template, returning it to the browser with a flash alert message to tell the user what happened.
592
-
593
- h4. Using +head+ To Build Header-Only Responses
594
-
595
- The +head+ method can be used to send responses with only headers to the browser. It provides a more obvious alternative to calling +render :nothing+. The +head+ method takes one parameter, which is interpreted as a hash of header names and values. For example, you can return only an error header:
596
-
597
- <ruby>
598
- head :bad_request
599
- </ruby>
600
-
601
- This would produce the following header:
602
-
603
- <shell>
604
- HTTP/1.1 400 Bad Request
605
- Connection: close
606
- Date: Sun, 24 Jan 2010 12:15:53 GMT
607
- Transfer-Encoding: chunked
608
- Content-Type: text/html; charset=utf-8
609
- X-Runtime: 0.013483
610
- Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
611
- Cache-Control: no-cache
612
- </shell>
613
-
614
- Or you can use other HTTP headers to convey other information:
615
-
616
- <ruby>
617
- head :created, :location => photo_path(@photo)
618
- </ruby>
619
-
620
- Which would produce:
621
-
622
- <shell>
623
- HTTP/1.1 201 Created
624
- Connection: close
625
- Date: Sun, 24 Jan 2010 12:16:44 GMT
626
- Transfer-Encoding: chunked
627
- Location: /photos/1
628
- Content-Type: text/html; charset=utf-8
629
- X-Runtime: 0.083496
630
- Set-Cookie: _blog_session=...snip...; path=/; HttpOnly
631
- Cache-Control: no-cache
632
- </shell>
633
-
634
- h3. Structuring Layouts
635
-
636
- When Rails renders a view as a response, it does so by combining the view with the current layout, using the rules for finding the current layout that were covered earlier in this guide. Within a layout, you have access to three tools for combining different bits of output to form the overall response:
637
-
638
- * Asset tags
639
- * +yield+ and +content_for+
640
- * Partials
641
-
642
- h4. Asset Tag Helpers
643
-
644
- Asset tag helpers provide methods for generating HTML that link views to feeds, JavaScript, stylesheets, images, videos and audios. There are six asset tag helpers available in Rails:
645
-
646
- * +auto_discovery_link_tag+
647
- * +javascript_include_tag+
648
- * +stylesheet_link_tag+
649
- * +image_tag+
650
- * +video_tag+
651
- * +audio_tag+
652
-
653
- You can use these tags in layouts or other views, although the +auto_discovery_link_tag+, +javascript_include_tag+, and +stylesheet_link_tag+, are most commonly used in the +&lt;head&gt;+ section of a layout.
654
-
655
- WARNING: The asset tag helpers do _not_ verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.
656
-
657
- h5. Linking to Feeds with the +auto_discovery_link_tag+
658
-
659
- The +auto_discovery_link_tag+ helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (+:rss+ or +:atom+), a hash of options that are passed through to url_for, and a hash of options for the tag:
660
-
661
- <erb>
662
- <%= auto_discovery_link_tag(:rss, {:action => "feed"},
663
- {:title => "RSS Feed"}) %>
664
- </erb>
665
-
666
- There are three tag options available for the +auto_discovery_link_tag+:
667
-
668
- * +:rel+ specifies the +rel+ value in the link. The default value is "alternate".
669
- * +:type+ specifies an explicit MIME type. Rails will generate an appropriate MIME type automatically.
670
- * +:title+ specifies the title of the link. The default value is the upshifted +:type+ value, for example, "ATOM" or "RSS".
671
-
672
- h5. Linking to JavaScript Files with the +javascript_include_tag+
673
-
674
- The +javascript_include_tag+ helper returns an HTML +script+ tag for each source provided.
675
-
676
- If you are using Rails with the "Asset Pipeline":asset_pipeline.html enabled, this helper will generate a link to +/assets/javascripts/+ rather than +public/javascripts+ which was used in earlier versions of Rails. This link is then served by the Sprockets gem, which was introduced in Rails 3.1.
677
-
678
- A JavaScript file within a Rails application or Rails engine goes in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+. These locations are explained in detail in the "Asset Organization section in the Asset Pipeline Guide":asset_pipeline.html#asset-organization
679
-
680
- You can specify a full path relative to the document root, or a URL, if you prefer. For example, to link to a JavaScript file that is inside a directory called +javascripts+ inside of one of +app/assets+, +lib/assets+ or +vendor/assets+, you would do this:
681
-
682
- <erb>
683
- <%= javascript_include_tag "main" %>
684
- </erb>
685
-
686
- Rails will then output a +script+ tag such as this:
687
-
688
- <html>
689
- <script src='/assets/main.js' type="text/javascript"></script>
690
- </html>
691
-
692
- The request to this asset is then served by the Sprockets gem.
693
-
694
- To include multiple files such as +app/assets/javascripts/main.js+ and +app/assets/javascripts/columns.js+ at the same time:
695
-
696
- <erb>
697
- <%= javascript_include_tag "main", "columns" %>
698
- </erb>
699
-
700
- To include +app/assets/javascripts/main.js+ and +app/assets/javascripts/photos/columns.js+:
701
-
702
- <erb>
703
- <%= javascript_include_tag "main", "/photos/columns" %>
704
- </erb>
705
-
706
- To include +http://example.com/main.js+:
707
-
708
- <erb>
709
- <%= javascript_include_tag "http://example.com/main.js" %>
710
- </erb>
711
-
712
- If the application does not use the asset pipeline, the +:defaults+ option loads jQuery by default:
713
-
714
- <erb>
715
- <%= javascript_include_tag :defaults %>
716
- </erb>
717
-
718
- Outputting +script+ tags such as this:
719
-
720
- <html>
721
- <script src="/javascripts/jquery.js" type="text/javascript"></script>
722
- <script src="/javascripts/jquery_ujs.js" type="text/javascript"></script>
723
- </html>
724
-
725
- These two files for jQuery, +jquery.js+ and +jquery_ujs.js+ must be placed inside +public/javascripts+ if the application doesn't use the asset pipeline. These files can be downloaded from the "jquery-rails repository on GitHub":https://github.com/indirect/jquery-rails/tree/master/vendor/assets/javascripts
726
-
727
- WARNING: If you are using the asset pipeline, this tag will render a +script+ tag for an asset called +defaults.js+, which would not exist in your application unless you've explicitly defined it to be.
728
-
729
- And you can in any case override the +:defaults+ expansion in <tt>config/application.rb</tt>:
730
-
731
- <ruby>
732
- config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)
733
- </ruby>
734
-
735
- You can also define new defaults:
736
-
737
- <ruby>
738
- config.action_view.javascript_expansions[:projects] = %w(projects.js tickets.js)
739
- </ruby>
740
-
741
- And use them by referencing them exactly like +:defaults+:
742
-
743
- <erb>
744
- <%= javascript_include_tag :projects %>
745
- </erb>
746
-
747
- When using <tt>:defaults</tt>, if an <tt>application.js</tt> file exists in <tt>public/javascripts</tt> it will be included as well at the end.
748
-
749
- Also, if the asset pipeline is disabled, the +:all+ expansion loads every JavaScript file in +public/javascripts+:
750
-
751
- <erb>
752
- <%= javascript_include_tag :all %>
753
- </erb>
754
-
755
- Note that your defaults of choice will be included first, so they will be available to all subsequently included files.
756
-
757
- You can supply the +:recursive+ option to load files in subfolders of +public/javascripts+ as well:
758
-
759
- <erb>
760
- <%= javascript_include_tag :all, :recursive => true %>
761
- </erb>
762
-
763
- If you're loading multiple JavaScript files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify +:cache => true+ in your +javascript_include_tag+:
764
-
765
- <erb>
766
- <%= javascript_include_tag "main", "columns", :cache => true %>
767
- </erb>
768
-
769
- By default, the combined file will be delivered as +javascripts/all.js+. You can specify a location for the cached asset file instead:
770
-
771
- <erb>
772
- <%= javascript_include_tag "main", "columns",
773
- :cache => 'cache/main/display' %>
774
- </erb>
775
-
776
- You can even use dynamic paths such as +cache/#{current_site}/main/display+.
777
-
778
- h5. Linking to CSS Files with the +stylesheet_link_tag+
779
-
780
- The +stylesheet_link_tag+ helper returns an HTML +&lt;link&gt;+ tag for each source provided.
781
-
782
- If you are using Rails with the "Asset Pipeline" enabled, this helper will generate a link to +/assets/stylesheets/+. This link is then processed by the Sprockets gem. A stylesheet file can be stored in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+.
783
-
784
- You can specify a full path relative to the document root, or a URL. For example, to link to a stylesheet file that is inside a directory called +stylesheets+ inside of one of +app/assets+, +lib/assets+ or +vendor/assets+, you would do this:
785
-
786
- <erb>
787
- <%= stylesheet_link_tag "main" %>
788
- </erb>
789
-
790
- To include +app/assets/stylesheets/main.css+ and +app/assets/stylesheets/columns.css+:
791
-
792
- <erb>
793
- <%= stylesheet_link_tag "main", "columns" %>
794
- </erb>
795
-
796
- To include +app/assets/stylesheets/main.css+ and +app/assets/stylesheets/photos/columns.css+:
797
-
798
- <erb>
799
- <%= stylesheet_link_tag "main", "/photos/columns" %>
800
- </erb>
801
-
802
- To include +http://example.com/main.css+:
803
-
804
- <erb>
805
- <%= stylesheet_link_tag "http://example.com/main.css" %>
806
- </erb>
807
-
808
- By default, the +stylesheet_link_tag+ creates links with +media="screen" rel="stylesheet" type="text/css"+. You can override any of these defaults by specifying an appropriate option (+:media+, +:rel+, or +:type+):
809
-
810
- <erb>
811
- <%= stylesheet_link_tag "main_print", :media => "print" %>
812
- </erb>
813
-
814
- If the asset pipeline is disabled, the +all+ option links every CSS file in +public/stylesheets+:
815
-
816
- <erb>
817
- <%= stylesheet_link_tag :all %>
818
- </erb>
819
-
820
- You can supply the +:recursive+ option to link files in subfolders of +public/stylesheets+ as well:
821
-
822
- <erb>
823
- <%= stylesheet_link_tag :all, :recursive => true %>
824
- </erb>
825
-
826
- If you're loading multiple CSS files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify +:cache => true+ in your +stylesheet_link_tag+:
827
-
828
- <erb>
829
- <%= stylesheet_link_tag "main", "columns", :cache => true %>
830
- </erb>
831
-
832
- By default, the combined file will be delivered as +stylesheets/all.css+. You can specify a location for the cached asset file instead:
833
-
834
- <erb>
835
- <%= stylesheet_link_tag "main", "columns",
836
- :cache => 'cache/main/display' %>
837
- </erb>
838
-
839
- You can even use dynamic paths such as +cache/#{current_site}/main/display+.
840
-
841
- h5. Linking to Images with the +image_tag+
842
-
843
- The +image_tag+ helper builds an HTML +&lt;img /&gt;+ tag to the specified file. By default, files are loaded from +public/images+.
844
-
845
- WARNING: Note that you must specify the extension of the image. Previous versions of Rails would allow you to just use the image name and would append +.png+ if no extension was given but Rails 3.0 does not.
846
-
847
- <erb>
848
- <%= image_tag "header.png" %>
849
- </erb>
850
-
851
- You can supply a path to the image if you like:
852
-
853
- <erb>
854
- <%= image_tag "icons/delete.gif" %>
855
- </erb>
856
-
857
- You can supply a hash of additional HTML options:
858
-
859
- <erb>
860
- <%= image_tag "icons/delete.gif", {:height => 45} %>
861
- </erb>
862
-
863
- You can also supply an alternate image to show on mouseover:
864
-
865
- <erb>
866
- <%= image_tag "home.gif", :onmouseover => "menu/home_highlight.gif" %>
867
- </erb>
868
-
869
- You can supply alternate text for the image which will be used if the user has images turned off in their browser. If you do not specify an alt text explicitly, it defaults to the file name of the file, capitalized and with no extension. For example, these two image tags would return the same code:
870
-
871
- <erb>
872
- <%= image_tag "home.gif" %>
873
- <%= image_tag "home.gif", :alt => "Home" %>
874
- </erb>
875
-
876
- You can also specify a special size tag, in the format "{width}x{height}":
877
-
878
- <erb>
879
- <%= image_tag "home.gif", :size => "50x20" %>
880
- </erb>
881
-
882
- In addition to the above special tags, you can supply a final hash of standard HTML options, such as +:class+, +:id+ or +:name+:
883
-
884
- <erb>
885
- <%= image_tag "home.gif", :alt => "Go Home",
886
- :id => "HomeImage",
887
- :class => 'nav_bar' %>
888
- </erb>
889
-
890
- h5. Linking to Videos with the +video_tag+
891
-
892
- The +video_tag+ helper builds an HTML 5 +&lt;video&gt;+ tag to the specified file. By default, files are loaded from +public/videos+.
893
-
894
- <erb>
895
- <%= video_tag "movie.ogg" %>
896
- </erb>
897
-
898
- Produces
899
-
900
- <erb>
901
- <video src="/videos/movie.ogg" />
902
- </erb>
903
-
904
- Like an +image_tag+ you can supply a path, either absolute, or relative to the +public/videos+ directory. Additionally you can specify the +:size => "#{width}x#{height}"+ option just like an +image_tag+. Video tags can also have any of the HTML options specified at the end (+id+, +class+ et al).
905
-
906
- The video tag also supports all of the +&lt;video&gt;+ HTML options through the HTML options hash, including:
907
-
908
- * +:poster => 'image_name.png'+, provides an image to put in place of the video before it starts playing.
909
- * +:autoplay => true+, starts playing the video on page load.
910
- * +:loop => true+, loops the video once it gets to the end.
911
- * +:controls => true+, provides browser supplied controls for the user to interact with the video.
912
- * +:autobuffer => true+, the video will pre load the file for the user on page load.
913
-
914
- You can also specify multiple videos to play by passing an array of videos to the +video_tag+:
915
-
916
- <erb>
917
- <%= video_tag ["trailer.ogg", "movie.ogg"] %>
918
- </erb>
919
-
920
- This will produce:
921
-
922
- <erb>
923
- <video><source src="trailer.ogg" /><source src="movie.ogg" /></video>
924
- </erb>
925
-
926
- h5. Linking to Audio Files with the +audio_tag+
927
-
928
- The +audio_tag+ helper builds an HTML 5 +&lt;audio&gt;+ tag to the specified file. By default, files are loaded from +public/audios+.
929
-
930
- <erb>
931
- <%= audio_tag "music.mp3" %>
932
- </erb>
933
-
934
- You can supply a path to the audio file if you like:
935
-
936
- <erb>
937
- <%= audio_tag "music/first_song.mp3" %>
938
- </erb>
939
-
940
- You can also supply a hash of additional options, such as +:id+, +:class+ etc.
941
-
942
- Like the +video_tag+, the +audio_tag+ has special options:
943
-
944
- * +:autoplay => true+, starts playing the audio on page load
945
- * +:controls => true+, provides browser supplied controls for the user to interact with the audio.
946
- * +:autobuffer => true+, the audio will pre load the file for the user on page load.
947
-
948
- h4. Understanding +yield+
949
-
950
- Within the context of a layout, +yield+ identifies a section where content from the view should be inserted. The simplest way to use this is to have a single +yield+, into which the entire contents of the view currently being rendered is inserted:
951
-
952
- <erb>
953
- <html>
954
- <head>
955
- </head>
956
- <body>
957
- <%= yield %>
958
- </body>
959
- </html>
960
- </erb>
961
-
962
- You can also create a layout with multiple yielding regions:
963
-
964
- <erb>
965
- <html>
966
- <head>
967
- <%= yield :head %>
968
- </head>
969
- <body>
970
- <%= yield %>
971
- </body>
972
- </html>
973
- </erb>
974
-
975
- The main body of the view will always render into the unnamed +yield+. To render content into a named +yield+, you use the +content_for+ method.
976
-
977
- h4. Using the +content_for+ Method
978
-
979
- The +content_for+ method allows you to insert content into a named +yield+ block in your layout. For example, this view would work with the layout that you just saw:
980
-
981
- <erb>
982
- <% content_for :head do %>
983
- <title>A simple page</title>
984
- <% end %>
985
-
986
- <p>Hello, Rails!</p>
987
- </erb>
988
-
989
- The result of rendering this page into the supplied layout would be this HTML:
990
-
991
- <erb>
992
- <html>
993
- <head>
994
- <title>A simple page</title>
995
- </head>
996
- <body>
997
- <p>Hello, Rails!</p>
998
- </body>
999
- </html>
1000
- </erb>
1001
-
1002
- The +content_for+ method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. It's also useful for inserting tags that load page-specific JavaScript or css files into the header of an otherwise generic layout.
1003
-
1004
- h4. Using Partials
1005
-
1006
- Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
1007
-
1008
- h5. Naming Partials
1009
-
1010
- To render a partial as part of a view, you use the +render+ method within the view:
1011
-
1012
- <ruby>
1013
- <%= render "menu" %>
1014
- </ruby>
1015
-
1016
- This will render a file named +_menu.html.erb+ at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:
1017
-
1018
- <ruby>
1019
- <%= render "shared/menu" %>
1020
- </ruby>
1021
-
1022
- That code will pull in the partial from +app/views/shared/_menu.html.erb+.
1023
-
1024
- h5. Using Partials to Simplify Views
1025
-
1026
- One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this:
1027
-
1028
- <erb>
1029
- <%= render "shared/ad_banner" %>
1030
-
1031
- <h1>Products</h1>
1032
-
1033
- <p>Here are a few of our fine products:</p>
1034
- ...
1035
-
1036
- <%= render "shared/footer" %>
1037
- </erb>
1038
-
1039
- Here, the +_ad_banner.html.erb+ and +_footer.html.erb+ partials could contain content that is shared among many pages in your application. You don't need to see the details of these sections when you're concentrating on a particular page.
1040
-
1041
- TIP: For content that is shared among all pages in your application, you can use partials directly from layouts.
1042
-
1043
- h5. Partial Layouts
1044
-
1045
- A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:
1046
-
1047
- <erb>
1048
- <%= render :partial => "link_area", :layout => "graybar" %>
1049
- </erb>
1050
-
1051
- This would look for a partial named +_link_area.html.erb+ and render it using the layout +_graybar.html.erb+. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master +layouts+ folder).
1052
-
1053
- Also note that explicitly specifying +:partial+ is required when passing additional options such as +:layout+.
1054
-
1055
- h5. Passing Local Variables
1056
-
1057
- You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content:
1058
-
1059
- * +new.html.erb+
1060
-
1061
- <erb>
1062
- <h1>New zone</h1>
1063
- <%= error_messages_for :zone %>
1064
- <%= render :partial => "form", :locals => { :zone => @zone } %>
1065
- </erb>
1066
-
1067
- * +edit.html.erb+
1068
-
1069
- <erb>
1070
- <h1>Editing zone</h1>
1071
- <%= error_messages_for :zone %>
1072
- <%= render :partial => "form", :locals => { :zone => @zone } %>
1073
- </erb>
1074
-
1075
- * +_form.html.erb+
1076
-
1077
- <erb>
1078
- <%= form_for(zone) do |f| %>
1079
- <p>
1080
- <b>Zone name</b><br />
1081
- <%= f.text_field :name %>
1082
- </p>
1083
- <p>
1084
- <%= f.submit %>
1085
- </p>
1086
- <% end %>
1087
- </erb>
1088
-
1089
- Although the same partial will be rendered into both views, Action View's submit helper will return "Create Zone" for the new action and "Update Zone" for the edit action.
1090
-
1091
- Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the +:object+ option:
1092
-
1093
- <erb>
1094
- <%= render :partial => "customer", :object => @new_customer %>
1095
- </erb>
1096
-
1097
- Within the +customer+ partial, the +customer+ variable will refer to +@new_customer+ from the parent view.
1098
-
1099
- WARNING: In previous versions of Rails, the default local variable would look for an instance variable with the same name as the partial in the parent. This behavior was deprecated in 2.3 and has been removed in Rails 3.0.
1100
-
1101
- If you have an instance of a model to render into a partial, you can use a shorthand syntax:
1102
-
1103
- <erb>
1104
- <%= render @customer %>
1105
- </erb>
1106
-
1107
- Assuming that the +@customer+ instance variable contains an instance of the +Customer+ model, this will use +_customer.html.erb+ to render it and will pass the local variable +customer+ into the partial which will refer to the +@customer+ instance variable in the parent view.
1108
-
1109
- h5. Rendering Collections
1110
-
1111
- Partials are very useful in rendering collections. When you pass a collection to a partial via the +:collection+ option, the partial will be inserted once for each member in the collection:
1112
-
1113
- * +index.html.erb+
1114
-
1115
- <erb>
1116
- <h1>Products</h1>
1117
- <%= render :partial => "product", :collection => @products %>
1118
- </erb>
1119
-
1120
- * +_product.html.erb+
1121
-
1122
- <erb>
1123
- <p>Product Name: <%= product.name %></p>
1124
- </erb>
1125
-
1126
- When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is +_product+, and within the +_product+ partial, you can refer to +product+ to get the instance that is being rendered.
1127
-
1128
- In Rails 3.0, there is also a shorthand for this. Assuming +@products+ is a collection of +product+ instances, you can simply write this in the +index.html.erb+ to produce the same result:
1129
-
1130
- <erb>
1131
- <h1>Products</h1>
1132
- <%= render @products %>
1133
- </erb>
1134
-
1135
- Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:
1136
-
1137
- In the event that the collection is empty, +render+ will return nil, so it should be fairly simple to provide alternative content.
1138
-
1139
- <erb>
1140
- <h1>Products</h1>
1141
- <%= render(@products) || 'There are no products available.' %>
1142
- </erb>
1143
-
1144
- * +index.html.erb+
1145
-
1146
- <erb>
1147
- <h1>Contacts</h1>
1148
- <%= render [customer1, employee1, customer2, employee2] %>
1149
- </erb>
1150
-
1151
- * +customers/_customer.html.erb+
1152
-
1153
- <erb>
1154
- <p>Customer: <%= customer.name %></p>
1155
- </erb>
1156
-
1157
- * +employees/_employee.html.erb+
1158
-
1159
- <erb>
1160
- <p>Employee: <%= employee.name %></p>
1161
- </erb>
1162
-
1163
- In this case, Rails will use the customer or employee partials as appropriate for each member of the collection.
1164
-
1165
- h5. Local Variables
1166
-
1167
- To use a custom local variable name within the partial, specify the +:as+ option in the call to the partial:
1168
-
1169
- <erb>
1170
- <%= render :partial => "product", :collection => @products, :as => :item %>
1171
- </erb>
1172
-
1173
- With this change, you can access an instance of the +@products+ collection as the +item+ local variable within the partial.
1174
-
1175
- You can also pass in arbitrary local variables to any partial you are rendering with the +:locals => {}+ option:
1176
-
1177
- <erb>
1178
- <%= render :partial => 'products', :collection => @products,
1179
- :as => :item, :locals => {:title => "Products Page"} %>
1180
- </erb>
1181
-
1182
- Would render a partial +_products.html.erb+ once for each instance of +product+ in the +@products+ instance variable passing the instance to the partial as a local variable called +item+ and to each partial, make the local variable +title+ available with the value +Products Page+.
1183
-
1184
- TIP: Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by +_counter+. For example, if you're rendering +@products+, within the partial you can refer to +product_counter+ to tell you how many times the partial has been rendered. This does not work in conjunction with the +:as => :value+ option.
1185
-
1186
- You can also specify a second partial to be rendered between instances of the main partial by using the +:spacer_template+ option:
1187
-
1188
- h5. Spacer Templates
1189
-
1190
- <erb>
1191
- <%= render :partial => @products, :spacer_template => "product_ruler" %>
1192
- </erb>
1193
-
1194
- Rails will render the +_product_ruler+ partial (with no data passed in to it) between each pair of +_product+ partials.
1195
-
1196
- h4. Using Nested Layouts
1197
-
1198
- You may find that your application requires a layout that differs slightly from your regular application layout to support one particular controller. Rather than repeating the main layout and editing it, you can accomplish this by using nested layouts (sometimes called sub-templates). Here's an example:
1199
-
1200
- Suppose you have the following +ApplicationController+ layout:
1201
-
1202
- * +app/views/layouts/application.html.erb+
1203
-
1204
- <erb>
1205
- <html>
1206
- <head>
1207
- <title><%= @page_title or 'Page Title' %></title>
1208
- <%= stylesheet_link_tag 'layout' %>
1209
- <style type="text/css"><%= yield :stylesheets %></style>
1210
- </head>
1211
- <body>
1212
- <div id="top_menu">Top menu items here</div>
1213
- <div id="menu">Menu items here</div>
1214
- <div id="content"><%= content_for?(:content) ? yield(:content) : yield %></div>
1215
- </body>
1216
- </html>
1217
- </erb>
1218
-
1219
- On pages generated by +NewsController+, you want to hide the top menu and add a right menu:
1220
-
1221
- * +app/views/layouts/news.html.erb+
1222
-
1223
- <erb>
1224
- <% content_for :stylesheets do %>
1225
- #top_menu {display: none}
1226
- #right_menu {float: right; background-color: yellow; color: black}
1227
- <% end %>
1228
- <% content_for :content do %>
1229
- <div id="right_menu">Right menu items here</div>
1230
- <%= content_for?(:news_content) ? yield(:news_content) : yield %>
1231
- <% end %>
1232
- <%= render :template => 'layouts/application' %>
1233
- </erb>
1234
-
1235
- That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div.
1236
-
1237
- There are several ways of getting similar results with different sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render :template => 'layouts/news'+ to base a new layout on the News layout. If you are sure you will not subtemplate the +News+ layout, you can replace the +content_for?(:news_content) ? yield(:news_content) : yield+ with simply +yield+.