rails 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (336) hide show
  1. data/bin/rails +8 -18
  2. metadata +118 -452
  3. data/CHANGELOG +0 -2071
  4. data/MIT-LICENSE +0 -20
  5. data/README +0 -256
  6. data/Rakefile +0 -411
  7. data/bin/about +0 -4
  8. data/bin/console +0 -3
  9. data/bin/dbconsole +0 -3
  10. data/bin/destroy +0 -3
  11. data/bin/generate +0 -3
  12. data/bin/performance/benchmarker +0 -3
  13. data/bin/performance/profiler +0 -3
  14. data/bin/performance/request +0 -3
  15. data/bin/plugin +0 -3
  16. data/bin/process/inspector +0 -3
  17. data/bin/process/reaper +0 -3
  18. data/bin/process/spawner +0 -3
  19. data/bin/runner +0 -3
  20. data/bin/server +0 -3
  21. data/builtin/rails_info/rails/info.rb +0 -125
  22. data/builtin/rails_info/rails/info_controller.rb +0 -9
  23. data/builtin/rails_info/rails/info_helper.rb +0 -2
  24. data/builtin/rails_info/rails_info_controller.rb +0 -2
  25. data/config.ru +0 -17
  26. data/configs/apache.conf +0 -40
  27. data/configs/databases/frontbase.yml +0 -28
  28. data/configs/databases/ibm_db.yml +0 -62
  29. data/configs/databases/mysql.yml +0 -57
  30. data/configs/databases/oracle.yml +0 -39
  31. data/configs/databases/postgresql.yml +0 -51
  32. data/configs/databases/sqlite2.yml +0 -19
  33. data/configs/databases/sqlite3.yml +0 -22
  34. data/configs/empty.log +0 -0
  35. data/configs/initializers/inflections.rb +0 -10
  36. data/configs/initializers/mime_types.rb +0 -5
  37. data/configs/initializers/new_rails_defaults.rb +0 -17
  38. data/configs/lighttpd.conf +0 -54
  39. data/configs/locales/en.yml +0 -5
  40. data/configs/routes.rb +0 -43
  41. data/dispatches/dispatch.fcgi +0 -24
  42. data/dispatches/dispatch.rb +0 -10
  43. data/dispatches/gateway.cgi +0 -97
  44. data/doc/README_FOR_APP +0 -5
  45. data/doc/guides/html/2_2_release_notes.html +0 -1185
  46. data/doc/guides/html/actioncontroller_basics.html +0 -1270
  47. data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
  48. data/doc/guides/html/association_basics.html +0 -2585
  49. data/doc/guides/html/authors.html +0 -240
  50. data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
  51. data/doc/guides/html/caching_with_rails.html +0 -583
  52. data/doc/guides/html/command_line.html +0 -434
  53. data/doc/guides/html/configuring.html +0 -438
  54. data/doc/guides/html/creating_plugins.html +0 -1594
  55. data/doc/guides/html/debugging_rails_applications.html +0 -1175
  56. data/doc/guides/html/finders.html +0 -1090
  57. data/doc/guides/html/form_helpers.html +0 -638
  58. data/doc/guides/html/getting_started_with_rails.html +0 -2066
  59. data/doc/guides/html/index.html +0 -349
  60. data/doc/guides/html/layouts_and_rendering.html +0 -1406
  61. data/doc/guides/html/migrations.html +0 -921
  62. data/doc/guides/html/routing_outside_in.html +0 -2213
  63. data/doc/guides/html/security.html +0 -1346
  64. data/doc/guides/html/testing_rails_applications.html +0 -1859
  65. data/doc/guides/source/2_2_release_notes.txt +0 -435
  66. data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
  67. data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
  68. data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
  69. data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
  70. data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
  71. data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
  72. data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
  73. data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
  74. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
  75. data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
  76. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
  77. data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
  78. data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
  79. data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
  80. data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
  81. data/doc/guides/source/active_record_basics.txt +0 -181
  82. data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
  83. data/doc/guides/source/association_basics.txt +0 -1840
  84. data/doc/guides/source/authors.txt +0 -39
  85. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
  86. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
  87. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
  88. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
  89. data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
  90. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
  91. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
  92. data/doc/guides/source/caching_with_rails.txt +0 -367
  93. data/doc/guides/source/command_line.txt +0 -147
  94. data/doc/guides/source/configuring.txt +0 -225
  95. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
  96. data/doc/guides/source/creating_plugins/appendix.txt +0 -46
  97. data/doc/guides/source/creating_plugins/controllers.txt +0 -59
  98. data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
  99. data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
  100. data/doc/guides/source/creating_plugins/gem.txt +0 -1
  101. data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
  102. data/doc/guides/source/creating_plugins/helpers.txt +0 -51
  103. data/doc/guides/source/creating_plugins/index.txt +0 -52
  104. data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
  105. data/doc/guides/source/creating_plugins/models.txt +0 -76
  106. data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
  107. data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
  108. data/doc/guides/source/debugging_rails_applications.txt +0 -733
  109. data/doc/guides/source/finders.txt +0 -668
  110. data/doc/guides/source/form_helpers.txt +0 -345
  111. data/doc/guides/source/getting_started_with_rails.txt +0 -1256
  112. data/doc/guides/source/images/belongs_to.png +0 -0
  113. data/doc/guides/source/images/bullet.gif +0 -0
  114. data/doc/guides/source/images/csrf.png +0 -0
  115. data/doc/guides/source/images/habtm.png +0 -0
  116. data/doc/guides/source/images/has_many.png +0 -0
  117. data/doc/guides/source/images/has_many_through.png +0 -0
  118. data/doc/guides/source/images/has_one.png +0 -0
  119. data/doc/guides/source/images/has_one_through.png +0 -0
  120. data/doc/guides/source/images/header_backdrop.png +0 -0
  121. data/doc/guides/source/images/icons/README +0 -5
  122. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  123. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  124. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  125. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  126. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  127. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  128. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  129. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  130. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  131. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  132. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  133. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  134. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  135. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  136. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  137. data/doc/guides/source/images/icons/caution.png +0 -0
  138. data/doc/guides/source/images/icons/example.png +0 -0
  139. data/doc/guides/source/images/icons/home.png +0 -0
  140. data/doc/guides/source/images/icons/important.png +0 -0
  141. data/doc/guides/source/images/icons/next.png +0 -0
  142. data/doc/guides/source/images/icons/note.png +0 -0
  143. data/doc/guides/source/images/icons/prev.png +0 -0
  144. data/doc/guides/source/images/icons/tip.png +0 -0
  145. data/doc/guides/source/images/icons/up.png +0 -0
  146. data/doc/guides/source/images/icons/warning.png +0 -0
  147. data/doc/guides/source/images/polymorphic.png +0 -0
  148. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  149. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  150. data/doc/guides/source/images/session_fixation.png +0 -0
  151. data/doc/guides/source/index.txt +0 -118
  152. data/doc/guides/source/layouts_and_rendering.txt +0 -982
  153. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
  154. data/doc/guides/source/migrations/changelog.txt +0 -5
  155. data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
  156. data/doc/guides/source/migrations/foreign_keys.txt +0 -8
  157. data/doc/guides/source/migrations/index.txt +0 -22
  158. data/doc/guides/source/migrations/rakeing_around.txt +0 -111
  159. data/doc/guides/source/migrations/scheming.txt +0 -47
  160. data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
  161. data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
  162. data/doc/guides/source/routing_outside_in.txt +0 -986
  163. data/doc/guides/source/security.txt +0 -984
  164. data/doc/guides/source/stylesheets/base.css +0 -358
  165. data/doc/guides/source/stylesheets/forms.css +0 -35
  166. data/doc/guides/source/stylesheets/more.css +0 -82
  167. data/doc/guides/source/templates/guides.html.erb +0 -97
  168. data/doc/guides/source/templates/inline.css +0 -165
  169. data/doc/guides/source/testing_rails_applications.txt +0 -995
  170. data/environments/boot.rb +0 -109
  171. data/environments/development.rb +0 -17
  172. data/environments/environment.rb +0 -75
  173. data/environments/production.rb +0 -24
  174. data/environments/test.rb +0 -22
  175. data/fresh_rakefile +0 -10
  176. data/helpers/application.rb +0 -15
  177. data/helpers/application_helper.rb +0 -3
  178. data/helpers/performance_test.rb +0 -9
  179. data/helpers/test_helper.rb +0 -38
  180. data/html/404.html +0 -30
  181. data/html/422.html +0 -30
  182. data/html/500.html +0 -33
  183. data/html/favicon.ico +0 -0
  184. data/html/images/rails.png +0 -0
  185. data/html/index.html +0 -274
  186. data/html/javascripts/application.js +0 -2
  187. data/html/javascripts/controls.js +0 -963
  188. data/html/javascripts/dragdrop.js +0 -973
  189. data/html/javascripts/effects.js +0 -1128
  190. data/html/javascripts/prototype.js +0 -4320
  191. data/html/robots.txt +0 -5
  192. data/lib/code_statistics.rb +0 -107
  193. data/lib/commands.rb +0 -17
  194. data/lib/commands/about.rb +0 -3
  195. data/lib/commands/console.rb +0 -45
  196. data/lib/commands/dbconsole.rb +0 -67
  197. data/lib/commands/destroy.rb +0 -6
  198. data/lib/commands/generate.rb +0 -6
  199. data/lib/commands/ncgi/listener +0 -86
  200. data/lib/commands/ncgi/tracker +0 -69
  201. data/lib/commands/performance/benchmarker.rb +0 -24
  202. data/lib/commands/performance/profiler.rb +0 -50
  203. data/lib/commands/performance/request.rb +0 -6
  204. data/lib/commands/plugin.rb +0 -967
  205. data/lib/commands/process/inspector.rb +0 -68
  206. data/lib/commands/process/reaper.rb +0 -149
  207. data/lib/commands/process/spawner.rb +0 -219
  208. data/lib/commands/process/spinner.rb +0 -57
  209. data/lib/commands/runner.rb +0 -48
  210. data/lib/commands/server.rb +0 -49
  211. data/lib/commands/servers/base.rb +0 -31
  212. data/lib/commands/servers/lighttpd.rb +0 -94
  213. data/lib/commands/servers/mongrel.rb +0 -69
  214. data/lib/commands/servers/new_mongrel.rb +0 -16
  215. data/lib/commands/servers/thin.rb +0 -25
  216. data/lib/commands/servers/webrick.rb +0 -66
  217. data/lib/commands/update.rb +0 -4
  218. data/lib/console_app.rb +0 -30
  219. data/lib/console_sandbox.rb +0 -6
  220. data/lib/console_with_helpers.rb +0 -26
  221. data/lib/dispatcher.rb +0 -24
  222. data/lib/fcgi_handler.rb +0 -237
  223. data/lib/initializer.rb +0 -1038
  224. data/lib/performance_test_help.rb +0 -5
  225. data/lib/rails/gem_builder.rb +0 -21
  226. data/lib/rails/gem_dependency.rb +0 -251
  227. data/lib/rails/mongrel_server/commands.rb +0 -342
  228. data/lib/rails/mongrel_server/handler.rb +0 -55
  229. data/lib/rails/plugin.rb +0 -124
  230. data/lib/rails/plugin/loader.rb +0 -152
  231. data/lib/rails/plugin/locator.rb +0 -100
  232. data/lib/rails/rack.rb +0 -6
  233. data/lib/rails/rack/logger.rb +0 -28
  234. data/lib/rails/rack/static.rb +0 -35
  235. data/lib/rails/vendor_gem_source_index.rb +0 -140
  236. data/lib/rails/version.rb +0 -9
  237. data/lib/rails_generator.rb +0 -43
  238. data/lib/rails_generator/base.rb +0 -263
  239. data/lib/rails_generator/commands.rb +0 -616
  240. data/lib/rails_generator/generated_attribute.rb +0 -46
  241. data/lib/rails_generator/generators/applications/app/USAGE +0 -9
  242. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -184
  243. data/lib/rails_generator/generators/components/controller/USAGE +0 -29
  244. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -37
  245. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
  246. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
  247. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  248. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
  249. data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
  250. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
  251. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
  252. data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
  253. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
  254. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
  255. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  256. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
  257. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
  258. data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
  259. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  260. data/lib/rails_generator/generators/components/migration/USAGE +0 -29
  261. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
  262. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
  263. data/lib/rails_generator/generators/components/model/USAGE +0 -27
  264. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -45
  265. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -19
  266. data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
  267. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
  268. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
  269. data/lib/rails_generator/generators/components/observer/USAGE +0 -13
  270. data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
  271. data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
  272. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
  273. data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
  274. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
  275. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
  276. data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
  277. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
  278. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
  279. data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
  280. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
  281. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  282. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  283. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  284. data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
  285. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  286. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  287. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -3
  288. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
  289. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  290. data/lib/rails_generator/generators/components/resource/USAGE +0 -23
  291. data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -74
  292. data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
  293. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
  294. data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
  295. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
  296. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -100
  297. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -85
  298. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
  299. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  300. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
  301. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
  302. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
  303. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
  304. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
  305. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
  306. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
  307. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
  308. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
  309. data/lib/rails_generator/lookup.rb +0 -249
  310. data/lib/rails_generator/manifest.rb +0 -53
  311. data/lib/rails_generator/options.rb +0 -150
  312. data/lib/rails_generator/scripts.rb +0 -89
  313. data/lib/rails_generator/scripts/destroy.rb +0 -29
  314. data/lib/rails_generator/scripts/generate.rb +0 -7
  315. data/lib/rails_generator/scripts/update.rb +0 -12
  316. data/lib/rails_generator/secret_key_generator.rb +0 -22
  317. data/lib/rails_generator/simple_logger.rb +0 -46
  318. data/lib/rails_generator/spec.rb +0 -44
  319. data/lib/railties_path.rb +0 -1
  320. data/lib/ruby_version_check.rb +0 -17
  321. data/lib/rubyprof_ext.rb +0 -35
  322. data/lib/source_annotation_extractor.rb +0 -102
  323. data/lib/tasks/annotations.rake +0 -20
  324. data/lib/tasks/databases.rake +0 -416
  325. data/lib/tasks/documentation.rake +0 -95
  326. data/lib/tasks/framework.rake +0 -118
  327. data/lib/tasks/gems.rake +0 -80
  328. data/lib/tasks/log.rake +0 -9
  329. data/lib/tasks/misc.rake +0 -56
  330. data/lib/tasks/rails.rb +0 -8
  331. data/lib/tasks/routes.rake +0 -17
  332. data/lib/tasks/statistics.rake +0 -18
  333. data/lib/tasks/testing.rake +0 -139
  334. data/lib/tasks/tmp.rake +0 -37
  335. data/lib/test_help.rb +0 -27
  336. data/lib/webrick_server.rb +0 -156
@@ -1,32 +0,0 @@
1
- == Request Forgery Protection ==
2
-
3
- Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission. The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you're following RESTful conventions you're already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that's where the request forgery protection comes in. As the name says, it protects from forged requests. The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access.
4
-
5
- If you generate a form like this:
6
-
7
- [source, ruby]
8
- -----------------------------------------
9
- <% form_for @user do |f| -%>
10
- <%= f.text_field :username %>
11
- <%= f.text_field :password -%>
12
- <% end -%>
13
- -----------------------------------------
14
-
15
- You will see how the token gets added as a hidden field:
16
-
17
- [source, html]
18
- -----------------------------------------
19
- <form action="/users/1" method="post">
20
- <div><!-- ... --><input type="hidden" value="67250ab105eb5ad10851c00a5621854a23af5489" name="authenticity_token"/></div>
21
- <!-- Fields -->
22
- </form>
23
- -----------------------------------------
24
-
25
- Rails adds this token to every form that's generated using the link:../form_helpers.html[form helpers], so most of the time you don't have to worry about it. If you're writing a form manually or need to add the token for another reason, it's available through the method `form_authenticity_token`:
26
-
27
- .Add a JavaScript variable containing the token for use with Ajax
28
- -----------------------------------------
29
- <%= javascript_tag "MyApp.authenticity_token = '#{form_authenticity_token}'" %>
30
- -----------------------------------------
31
-
32
- The link:../security.html[Security Guide] has more about this and a lot of other security-related issues that you should be aware of when developing a web application.
@@ -1,119 +0,0 @@
1
- == Filters ==
2
-
3
- Filters are methods that are run before, after or "around" a controller action. For example, one filter might check to see if the logged in user has the right credentials to access that particular controller or action. Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application. A common, simple filter is one which requires that a user is logged in for an action to be run. You can define the filter method this way:
4
-
5
- [source, ruby]
6
- ---------------------------------
7
- class ApplicationController < ActionController::Base
8
-
9
- private
10
-
11
- def require_login
12
- unless logged_in?
13
- flash[:error] = "You must be logged in to access this section"
14
- redirect_to new_login_url # Prevents the current action from running
15
- end
16
- end
17
-
18
- # The logged_in? method simply returns true if the user is logged in and
19
- # false otherwise. It does this by "booleanizing" the current_user method
20
- # we created previously using a double ! operator. Note that this is not
21
- # common in Ruby and is discouraged unless you really mean to convert something
22
- # into true or false.
23
- def logged_in?
24
- !!current_user
25
- end
26
-
27
- end
28
- ---------------------------------
29
-
30
- The method simply stores an error message in the flash and redirects to the login form if the user is not logged in. If a before filter (a filter which is run before the action) renders or redirects, the action will not run. If there are additional filters scheduled to run after the rendering or redirecting filter, they are also cancelled. To use this filter in a controller, use the `before_filter` method:
31
-
32
- [source, ruby]
33
- ---------------------------------
34
- class ApplicationController < ActionController::Base
35
-
36
- before_filter :require_login
37
-
38
- end
39
- ---------------------------------
40
-
41
- In this example, the filter is added to ApplicationController and thus all controllers in the application. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_filter` :
42
-
43
- [source, ruby]
44
- ---------------------------------
45
- class LoginsController < Application
46
-
47
- skip_before_filter :require_login, :only => [:new, :create]
48
-
49
- end
50
- ---------------------------------
51
-
52
- Now, the +LoginsController+'s "new" and "create" actions will work as before without requiring the user to be logged in. The `:only` option is used to only skip this filter for these actions, and there is also an `:except` option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place.
53
-
54
- === After Filters and Around Filters ===
55
-
56
- In addition to the before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that's about to be sent to the client. Obviously, after filters can not stop the action from running. Around filters are responsible for running the action, but they can choose not to, which is the around filter's way of stopping it.
57
-
58
- [source, ruby]
59
- ---------------------------------
60
- # Example taken from the Rails API filter documentation:
61
- # http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
62
- class ApplicationController < Application
63
-
64
- around_filter :catch_exceptions
65
-
66
- private
67
-
68
- def catch_exceptions
69
- yield
70
- rescue => exception
71
- logger.debug "Caught exception! #{exception}"
72
- raise
73
- end
74
-
75
- end
76
- ---------------------------------
77
-
78
- === Other Ways to Use Filters ===
79
-
80
- While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing.
81
-
82
- The first is to use a block directly with the *_filter methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
83
-
84
- [source, ruby]
85
- ---------------------------------
86
- class ApplicationController < ActionController::Base
87
-
88
- before_filter { |controller| redirect_to new_login_url unless controller.send(:logged_in?) }
89
-
90
- end
91
- ---------------------------------
92
-
93
- Note that the filter in this case uses `send` because the `logged_in?` method is private and the filter is not run in the scope of the controller. This is not the recommended way to implement this particular filter, but in more simple cases it might be useful.
94
-
95
- The second way is to use a class (actually, any object that responds to the right methods will do) to handle the filtering. This is useful in cases that are more complex than can not be implemented in a readable and reusable way using the two other methods. As an example, you could rewrite the login filter again to use a class:
96
-
97
- [source, ruby]
98
- ---------------------------------
99
- class ApplicationController < ActionController::Base
100
-
101
- before_filter LoginFilter
102
-
103
- end
104
-
105
- class LoginFilter
106
-
107
- def self.filter(controller)
108
- unless logged_in?
109
- controller.flash[:error] = "You must be logged in to access this section"
110
- controller.redirect_to controller.new_login_url
111
- end
112
- end
113
-
114
- end
115
- ---------------------------------
116
-
117
- Again, this is not an ideal example for this filter, because it's not run in the scope of the controller but gets the controller passed as an argument. The filter class has a class method `filter` which gets run before or after the action, depending on if it's a before or after filter. Classes used as around filters can also use the same `filter` method, which will get run in the same way. The method must `yield` to execute the action. Alternatively, it can have both a `before` and an `after` method that are run before and after the action.
118
-
119
- The Rails API documentation has link:http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html[more information on using filters].
@@ -1,24 +0,0 @@
1
- == HTTP Basic Authentication ==
2
-
3
- Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, `authenticate_or_request_with_http_basic`.
4
-
5
- [source, ruby]
6
- -------------------------------------
7
- class AdminController < ApplicationController
8
-
9
- USERNAME, PASSWORD = "humbaba", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
10
-
11
- before_filter :authenticate
12
-
13
- private
14
-
15
- def authenticate
16
- authenticate_or_request_with_http_basic do |username, password|
17
- username == USERNAME && Digest::SHA1.hexdigest(password) == PASSWORD
18
- end
19
- end
20
-
21
- end
22
- -------------------------------------
23
-
24
- With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.
@@ -1,40 +0,0 @@
1
- Action Controller basics
2
- =======================
3
-
4
- In this guide you will learn how controllers work and how they fit into the request cycle in your application. After reading this guide, you will be able to:
5
-
6
- * Follow the flow of a request through a controller
7
- * Understand why and how to store data in the session or cookies
8
- * Work with filters to execute code during request processing
9
- * Use Action Controller's built-in HTTP authentication
10
- * Stream data directly to the user's browser
11
- * Filter sensitive parameters so they do not appear in the application's log
12
- * Deal with exceptions that may be raised during request processing
13
-
14
- include::introduction.txt[]
15
-
16
- include::methods.txt[]
17
-
18
- include::params.txt[]
19
-
20
- include::session.txt[]
21
-
22
- include::cookies.txt[]
23
-
24
- include::filters.txt[]
25
-
26
- include::verification.txt[]
27
-
28
- include::csrf.txt[]
29
-
30
- include::request_response_objects.txt[]
31
-
32
- include::http_auth.txt[]
33
-
34
- include::streaming.txt[]
35
-
36
- include::parameter_filtering.txt[]
37
-
38
- include::rescue.txt[]
39
-
40
- include::changelog.txt[]
@@ -1,9 +0,0 @@
1
- == What Does a Controller do? ==
2
-
3
- Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straight-forward as possible.
4
-
5
- For most conventional RESTful applications, the controller will receive the request (this is invisible to you as the developer), fetch or save data from a model and use a view to create HTML output. If your controller needs to do things a little differently, that's not a problem, this is just the most common way for a controller to work.
6
-
7
- A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model.
8
-
9
- NOTE: For more details on the routing process, see link:../routing_outside_in.html[Rails Routing from the Outside In].
@@ -1,39 +0,0 @@
1
- == Methods and Actions ==
2
-
3
- A controller is a Ruby class which inherits from ApplicationController and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the public method with the same name as the action.
4
-
5
- [source, ruby]
6
- ----------------------------------------------
7
- class ClientsController < ApplicationController
8
-
9
- # Actions are public methods
10
- def new
11
- end
12
-
13
- # Action methods are responsible for producing output
14
- def edit
15
- end
16
-
17
- # Helper methods are private and can not be used as actions
18
- private
19
-
20
- def foo
21
- end
22
-
23
- end
24
- ----------------------------------------------
25
-
26
- There's no rule saying a method on a controller has to be an action; they may well be used for other purposes such as filters, which will be covered later in this guide.
27
-
28
- As an example, if a user goes to `/clients/new` in your application to add a new client, Rails will create an instance of ClientsController and run the `new` method. Note that the empty method from the example above could work just fine because Rails will by default render the `new.html.erb` view unless the action says otherwise. The `new` method could make available to the view a `@client` instance variable by creating a new Client:
29
-
30
- [source, ruby]
31
- ----------------------------------------------
32
- def new
33
- @client = Client.new
34
- end
35
- ----------------------------------------------
36
-
37
- The link:../layouts_and_rendering.html[Layouts & rendering guide] explains this in more detail.
38
-
39
- ApplicationController inherits from ActionController::Base, which defines a number of helpful methods. This guide will cover some of these, but if you're curious to see what's in there, you can see all of them in the API documentation or in the source itself.
@@ -1,14 +0,0 @@
1
- == Parameter Filtering ==
2
-
3
- Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The `filter_parameter_logging` method can be used to filter out sensitive information from the log. It works by replacing certain values in the `params` hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password":
4
-
5
- [source, ruby]
6
- -------------------------
7
- class ApplicationController < ActionController::Base
8
-
9
- filter_parameter_logging :password
10
-
11
- end
12
- -------------------------
13
-
14
- The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true.
@@ -1,93 +0,0 @@
1
- == Parameters ==
2
-
3
- You will probably want to access data sent in by the user or other parameters in your controller actions. There are two kinds of parameters possible in a web application. The first are parameters that are sent as part of the URL, called query string parameters. The query string is everything after "?" in the URL. The second type of parameter is usually referred to as POST data. This information usually comes from a HTML form which has been filled in by the user. It's called POST data because it can only be sent as part of an HTTP POST request. Rails does not make any distinction between query string parameters and POST parameters, and both are available in the `params` hash in your controller:
4
-
5
- [source, ruby]
6
- -------------------------------------
7
- class ClientsController < ActionController::Base
8
-
9
- # This action uses query string parameters because it gets run by a HTTP
10
- # GET request, but this does not make any difference to the way in which
11
- # the parameters are accessed. The URL for this action would look like this
12
- # in order to list activated clients: /clients?status=activated
13
- def index
14
- if params[:status] = "activated"
15
- @clients = Client.activated
16
- else
17
- @clients = Client.unativated
18
- end
19
- end
20
-
21
- # This action uses POST parameters. They are most likely coming from an HTML
22
- # form which the user has submitted. The URL for this RESTful request will
23
- # be "/clients", and the data will be sent as part of the request body.
24
- def create
25
- @client = Client.new(params[:client])
26
- if @client.save
27
- redirect_to @client
28
- else
29
- # This line overrides the default rendering behavior, which would have been
30
- # to render the "create" view.
31
- render :action => "new"
32
- end
33
- end
34
-
35
- end
36
- -------------------------------------
37
-
38
- === Hash and Array Parameters ===
39
-
40
- The params hash is not limited to one-dimensional keys and values. It can contain arrays and (nested) hashes. To send an array of values, append "[]" to the key name:
41
-
42
- -------------------------------------
43
- GET /clients?ids[]=1&ids[]=2&ids[]=3
44
- -------------------------------------
45
-
46
- NOTE: The actual URL in this example will be encoded as "/clients?ids%5b%5d=1&ids%5b%5d=2&ids%5b%5b=3" as [ and ] are not allowed in URLs. Most of the time you don't have to worry about this because the browser will take care of it for you, and Rails will decode it back when it receives it, but if you ever find yourself having to send those requests to the server manually you have to keep this in mind.
47
-
48
- The value of `params[:ids]` will now be `["1", "2", "3"]`. Note that parameter values are always strings; Rails makes no attempt to guess or cast the type.
49
-
50
- To send a hash you include the key name inside the brackets:
51
-
52
- -------------------------------------
53
- <form action="/clients" method="post">
54
- <input type="text" name="client[name]" value="Acme" />
55
- <input type="text" name="client[phone]" value="12345" />
56
- <input type="text" name="client[address][postcode]" value="12345" />
57
- <input type="text" name="client[address][city]" value="Carrot City" />
58
- </form>
59
- -------------------------------------
60
-
61
- The value of `params[:client]` when this form is submitted will be `{"name" => "Acme", "phone" => "12345", "address" => {"postcode" => "12345", "city" => "Carrot City"}}`. Note the nested hash in `params[:client][:address]`.
62
-
63
- Note that the params hash is actually an instance of HashWithIndifferentAccess from Active Support which is a subclass of Hash which lets you use symbols and strings interchangeably as keys.
64
-
65
- === Routing Parameters ===
66
-
67
- The `params` hash will always contain the `:controller` and `:action` keys, but you should use the methods `controller_name` and `action_name` instead to access these values. Any other parameters defined by the routing, such as `:id` will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the `:status` parameter in a "pretty" URL:
68
-
69
- [source, ruby]
70
- ------------------------------------
71
- # ...
72
- map.connect "/clients/:status", :controller => "clients", :action => "index", :foo => "bar"
73
- # ...
74
- ------------------------------------
75
-
76
- In this case, when a user opens the URL `/clients/active`, `params[:status]` will be set to "active". When this route is used, `params[:foo]` will also be set to "bar" just like it was passed in the query string in the same way `params[:action]` will contain "index".
77
-
78
- === `default_url_options` ===
79
-
80
- You can set global default parameters that will be used when generating URLs with `default_url_options`. To do this, define a method with that name in your controller:
81
-
82
- ------------------------------------
83
- class ApplicationController < ActionController::Base
84
-
85
- #The options parameter is the hash passed in to +url_for+
86
- def default_url_options(options)
87
- {:locale => I18n.locale}
88
- end
89
-
90
- end
91
- ------------------------------------
92
-
93
- These options will be used as a starting-point when generating, so it's possible they'll be overridden by +url_for+. Because this method is defined in the controller, you can define it on ApplicationController so it would be used for all URL generation, or you could define it on only one controller for all URLs generated there.
@@ -1,43 +0,0 @@
1
- == The +request+ and +response+ Objects ==
2
-
3
- In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The `request` method contains an instance of AbstractRequest and the `response` method returns a +response+ object representing what is going to be sent back to the client.
4
-
5
- === The +request+ Object ===
6
-
7
- The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the link:http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html[API documentation]. Among the properties that you can access on this object are:
8
-
9
- * host - The hostname used for this request.
10
- * domain - The hostname without the first segment (usually "www").
11
- * format - The content type requested by the client.
12
- * method - The HTTP method used for the request.
13
- * get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head.
14
- * headers - Returns a hash containing the headers associated with the request.
15
- * port - The port number (integer) used for the request.
16
- * protocol - The protocol used for the request.
17
- * query_string - The query string part of the URL - everything after "?".
18
- * remote_ip - The IP address of the client.
19
- * url - The entire URL used for the request.
20
-
21
- ==== +path_parameters+, +query_parameters+ and +request_parameters+ ====
22
-
23
- Rails collects all of the parameters sent along with the request in the `params` hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The `query_parameters` hash contains parameters that were sent as part of the query string while the `request_parameters` hash contains parameters sent as part of the post body. The `path_parameters` hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action.
24
-
25
- === The +response+ Object ===
26
-
27
- The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.
28
-
29
- * body - This is the string of data being sent back to the client. This is most often HTML.
30
- * status - The HTTP status code for the response, like 200 for a successful request or 404 for file not found.
31
- * location - The URL the client is being redirected to, if any.
32
- * content_type - The content type of the response.
33
- * charset - The character set being used for the response. Default is "utf8".
34
- * headers - Headers used for the response.
35
-
36
- ==== Setting Custom Headers ====
37
-
38
- If you want to set custom headers for a response then `response.headers` is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them - like "Content-Type" - automatically. If you want to add or change a header, just assign it to `headers` with the name and value:
39
-
40
- [source, ruby]
41
- -------------------------------------
42
- response.headers["Content-Type"] = "application/pdf"
43
- -------------------------------------
@@ -1,67 +0,0 @@
1
- == Rescue ==
2
-
3
- Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the ActiveRecord::RecordNotFound exception. Rails' default exception handling displays a 500 Server Error message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple "500 Server Error" message to the user, or a "404 Not Found" if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they're displayed to the user. There are several levels of exception handling available in a Rails application:
4
-
5
- === The Default 500 and 404 Templates ===
6
-
7
- By default a production application will render either a 404 or a 500 error message. These messages are contained in static HTML files in the `public` folder, in `404.html` and `500.html` respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can't use RHTML or layouts in them, just plain HTML.
8
-
9
- === `rescue_from` ===
10
-
11
- If you want to do something a bit more elaborate when catching errors, you can use `rescue_from`, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses. When an exception occurs which is caught by a +rescue_from+ directive, the exception object is passed to the handler. The handler can be a method or a Proc object passed to the `:with` option. You can also use a block directly instead of an explicit Proc object.
12
-
13
- Here's how you can use +rescue_from+ to intercept all ActiveRecord::RecordNotFound errors and do something with them.
14
-
15
- [source, ruby]
16
- -----------------------------------
17
- class ApplicationController < ActionController::Base
18
-
19
- rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
20
-
21
- private
22
-
23
- def record_not_found
24
- render :text => "404 Not Found", :status => 404
25
- end
26
-
27
- end
28
- -----------------------------------
29
-
30
- Of course, this example is anything but elaborate and doesn't improve on the default exception handling at all, but once you can catch all those exceptions you're free to do whatever you want with them. For example, you could create custom exception classes that will be thrown when a user doesn't have access to a certain section of your application:
31
-
32
- [source, ruby]
33
- -----------------------------------
34
- class ApplicationController < ActionController::Base
35
-
36
- rescue_from User::NotAuthorized, :with => :user_not_authorized
37
-
38
- private
39
-
40
- def user_not_authorized
41
- flash[:error] = "You don't have access to this section."
42
- redirect_to :back
43
- end
44
-
45
- end
46
-
47
- class ClientsController < ApplicationController
48
-
49
- # Check that the user has the right authorization to access clients.
50
- before_filter :check_authorization
51
-
52
- # Note how the actions don't have to worry about all the auth stuff.
53
- def edit
54
- @client = Client.find(params[:id])
55
- end
56
-
57
- private
58
-
59
- # If the user is not authorized, just throw the exception.
60
- def check_authorization
61
- raise User::NotAuthorized unless current_user.admin?
62
- end
63
-
64
- end
65
- -----------------------------------
66
-
67
- NOTE: Certain exceptions are only rescuable from the ApplicationController class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's link:http://m.onkey.org/2008/7/20/rescue-from-dispatching[article] on the subject for more information.