jets 1.4.11 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +6 -5
- data/jets.gemspec +3 -2
- data/lib/jets.rb +8 -2
- data/lib/jets/builders/tidy.rb +2 -1
- data/lib/jets/commands/db.rb +3 -3
- data/lib/jets/commands/db/tasks.rb +5 -4
- data/lib/jets/generator.rb +3 -2
- data/lib/jets/router.rb +29 -4
- data/lib/jets/router/scope.rb +30 -0
- data/lib/jets/version.rb +1 -1
- data/vendor/rails/Brewfile +13 -0
- data/vendor/rails/CODE_OF_CONDUCT.md +12 -0
- data/vendor/rails/CONTRIBUTING.md +49 -0
- data/vendor/rails/Gemfile +174 -0
- data/vendor/rails/Gemfile.lock +564 -0
- data/vendor/rails/MIT-LICENSE +20 -0
- data/vendor/rails/RAILS_VERSION +1 -0
- data/vendor/rails/README.md +97 -0
- data/vendor/rails/RELEASING_RAILS.md +225 -0
- data/vendor/rails/Rakefile +72 -0
- data/vendor/rails/actionpack/CHANGELOG.md +407 -0
- data/vendor/rails/actionpack/MIT-LICENSE +21 -0
- data/vendor/rails/actionpack/README.rdoc +57 -0
- data/vendor/rails/actionpack/Rakefile +40 -0
- data/vendor/rails/actionpack/actionpack.gemspec +38 -0
- data/vendor/rails/actionpack/bin/test +5 -0
- data/vendor/rails/actionpack/lib/abstract_controller.rb +27 -0
- data/vendor/rails/actionpack/lib/abstract_controller/asset_paths.rb +12 -0
- data/vendor/rails/actionpack/lib/abstract_controller/base.rb +265 -0
- data/vendor/rails/actionpack/lib/abstract_controller/caching.rb +66 -0
- data/vendor/rails/actionpack/lib/abstract_controller/caching/fragments.rb +166 -0
- data/vendor/rails/actionpack/lib/abstract_controller/callbacks.rb +212 -0
- data/vendor/rails/actionpack/lib/abstract_controller/collector.rb +43 -0
- data/vendor/rails/actionpack/lib/abstract_controller/error.rb +6 -0
- data/vendor/rails/actionpack/lib/abstract_controller/helpers.rb +194 -0
- data/vendor/rails/actionpack/lib/abstract_controller/logger.rb +14 -0
- data/vendor/rails/actionpack/lib/abstract_controller/railties/routes_helpers.rb +20 -0
- data/vendor/rails/actionpack/lib/abstract_controller/rendering.rb +127 -0
- data/vendor/rails/actionpack/lib/abstract_controller/translation.rb +31 -0
- data/vendor/rails/actionpack/lib/abstract_controller/url_for.rb +35 -0
- data/vendor/rails/actionpack/lib/action_controller.rb +66 -0
- data/vendor/rails/actionpack/lib/action_controller/api.rb +149 -0
- data/vendor/rails/actionpack/lib/action_controller/api/api_rendering.rb +16 -0
- data/vendor/rails/actionpack/lib/action_controller/base.rb +276 -0
- data/vendor/rails/actionpack/lib/action_controller/caching.rb +46 -0
- data/vendor/rails/actionpack/lib/action_controller/form_builder.rb +50 -0
- data/vendor/rails/actionpack/lib/action_controller/log_subscriber.rb +78 -0
- data/vendor/rails/actionpack/lib/action_controller/metal.rb +256 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/conditional_get.rb +274 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/cookies.rb +16 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/data_streaming.rb +152 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/exceptions.rb +53 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/flash.rb +61 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/force_ssl.rb +99 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/head.rb +60 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/helpers.rb +123 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/http_authentication.rb +519 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/implicit_render.rb +73 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/instrumentation.rb +107 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/live.rb +312 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/mime_responds.rb +313 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/params_wrapper.rb +293 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/redirecting.rb +133 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/renderers.rb +181 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/rendering.rb +122 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/request_forgery_protection.rb +445 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/rescue.rb +28 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/streaming.rb +223 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/strong_parameters.rb +1086 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/testing.rb +16 -0
- data/vendor/rails/actionpack/lib/action_controller/metal/url_for.rb +58 -0
- data/vendor/rails/actionpack/lib/action_controller/railtie.rb +89 -0
- data/vendor/rails/actionpack/lib/action_controller/railties/helpers.rb +24 -0
- data/vendor/rails/actionpack/lib/action_controller/renderer.rb +117 -0
- data/vendor/rails/actionpack/lib/action_controller/template_assertions.rb +11 -0
- data/vendor/rails/actionpack/lib/action_controller/test_case.rb +629 -0
- data/vendor/rails/actionpack/lib/action_dispatch.rb +112 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/cache.rb +220 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/filter_parameters.rb +84 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/headers.rb +132 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/mime_negotiation.rb +170 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/mime_type.rb +342 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/mime_types.rb +50 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/parameter_filter.rb +86 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/parameters.rb +126 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/rack_cache.rb +63 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/request.rb +430 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/response.rb +520 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/upload.rb +84 -0
- data/vendor/rails/actionpack/lib/action_dispatch/http/url.rb +350 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey.rb +7 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/formatter.rb +189 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/gtg/builder.rb +164 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/nfa/builder.rb +78 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/nodes/node.rb +140 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/parser.rb +199 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/parser.y +50 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/parser_extras.rb +31 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/path/pattern.rb +198 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/route.rb +203 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/router.rb +156 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/router/utils.rb +102 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/routes.rb +82 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/scanner.rb +64 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/visitors.rb +268 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/vendor/rails/actionpack/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb +36 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/cookies.rb +685 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +205 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb +147 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/executor.rb +21 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/flash.rb +300 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/public_exceptions.rb +57 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/reloader.rb +12 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb +183 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/request_id.rb +43 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +92 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/session/cache_store.rb +54 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +117 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb +28 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +62 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/ssl.rb +150 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/stack.rb +116 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/static.rb +130 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb +161 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/vendor/rails/actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/vendor/rails/actionpack/lib/action_dispatch/railtie.rb +55 -0
- data/vendor/rails/actionpack/lib/action_dispatch/request/session.rb +234 -0
- data/vendor/rails/actionpack/lib/action_dispatch/request/utils.rb +78 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing.rb +260 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/endpoint.rb +17 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/inspector.rb +225 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/mapper.rb +2267 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +352 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/redirection.rb +201 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/route_set.rb +890 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/routes_proxy.rb +69 -0
- data/vendor/rails/actionpack/lib/action_dispatch/routing/url_for.rb +236 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_test_case.rb +147 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/server.rb +31 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/vendor/rails/actionpack/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/assertions.rb +24 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/assertions/response.rb +107 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/assertions/routing.rb +222 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/integration.rb +652 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/test_process.rb +50 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/test_request.rb +71 -0
- data/vendor/rails/actionpack/lib/action_dispatch/testing/test_response.rb +53 -0
- data/vendor/rails/actionpack/lib/action_pack.rb +26 -0
- data/vendor/rails/actionpack/lib/action_pack/gem_version.rb +17 -0
- data/vendor/rails/actionpack/lib/action_pack/version.rb +10 -0
- data/vendor/rails/actionpack/test/abstract/callbacks_test.rb +270 -0
- data/vendor/rails/actionpack/test/abstract/collector_test.rb +65 -0
- data/vendor/rails/actionpack/test/abstract/translation_test.rb +79 -0
- data/vendor/rails/actionpack/test/abstract_unit.rb +457 -0
- data/vendor/rails/actionpack/test/assertions/response_assertions_test.rb +141 -0
- data/vendor/rails/actionpack/test/controller/action_pack_assertions_test.rb +493 -0
- data/vendor/rails/actionpack/test/controller/api/conditional_get_test.rb +59 -0
- data/vendor/rails/actionpack/test/controller/api/data_streaming_test.rb +28 -0
- data/vendor/rails/actionpack/test/controller/api/force_ssl_test.rb +22 -0
- data/vendor/rails/actionpack/test/controller/api/implicit_render_test.rb +17 -0
- data/vendor/rails/actionpack/test/controller/api/params_wrapper_test.rb +28 -0
- data/vendor/rails/actionpack/test/controller/api/redirect_to_test.rb +21 -0
- data/vendor/rails/actionpack/test/controller/api/renderers_test.rb +50 -0
- data/vendor/rails/actionpack/test/controller/api/url_for_test.rb +22 -0
- data/vendor/rails/actionpack/test/controller/api/with_cookies_test.rb +23 -0
- data/vendor/rails/actionpack/test/controller/api/with_helpers_test.rb +44 -0
- data/vendor/rails/actionpack/test/controller/base_test.rb +323 -0
- data/vendor/rails/actionpack/test/controller/caching_test.rb +511 -0
- data/vendor/rails/actionpack/test/controller/content_type_test.rb +169 -0
- data/vendor/rails/actionpack/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/vendor/rails/actionpack/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/vendor/rails/actionpack/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/vendor/rails/actionpack/test/controller/default_url_options_with_before_action_test.rb +28 -0
- data/vendor/rails/actionpack/test/controller/filters_test.rb +1050 -0
- data/vendor/rails/actionpack/test/controller/flash_hash_test.rb +216 -0
- data/vendor/rails/actionpack/test/controller/flash_test.rb +373 -0
- data/vendor/rails/actionpack/test/controller/force_ssl_test.rb +333 -0
- data/vendor/rails/actionpack/test/controller/form_builder_test.rb +19 -0
- data/vendor/rails/actionpack/test/controller/helper_test.rb +295 -0
- data/vendor/rails/actionpack/test/controller/http_basic_authentication_test.rb +179 -0
- data/vendor/rails/actionpack/test/controller/http_digest_authentication_test.rb +282 -0
- data/vendor/rails/actionpack/test/controller/http_token_authentication_test.rb +216 -0
- data/vendor/rails/actionpack/test/controller/integration_test.rb +1136 -0
- data/vendor/rails/actionpack/test/controller/live_stream_test.rb +518 -0
- data/vendor/rails/actionpack/test/controller/localized_templates_test.rb +48 -0
- data/vendor/rails/actionpack/test/controller/log_subscriber_test.rb +371 -0
- data/vendor/rails/actionpack/test/controller/metal/renderers_test.rb +50 -0
- data/vendor/rails/actionpack/test/controller/metal_test.rb +32 -0
- data/vendor/rails/actionpack/test/controller/mime/accept_format_test.rb +94 -0
- data/vendor/rails/actionpack/test/controller/mime/respond_to_test.rb +843 -0
- data/vendor/rails/actionpack/test/controller/new_base/bare_metal_test.rb +184 -0
- data/vendor/rails/actionpack/test/controller/new_base/base_test.rb +131 -0
- data/vendor/rails/actionpack/test/controller/new_base/content_negotiation_test.rb +28 -0
- data/vendor/rails/actionpack/test/controller/new_base/content_type_test.rb +116 -0
- data/vendor/rails/actionpack/test/controller/new_base/middleware_test.rb +112 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_action_test.rb +314 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_body_test.rb +172 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_context_test.rb +54 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_file_test.rb +72 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_html_test.rb +192 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_implicit_action_test.rb +59 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_layout_test.rb +128 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_partial_test.rb +62 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_plain_test.rb +170 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_streaming_test.rb +116 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_template_test.rb +240 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_test.rb +142 -0
- data/vendor/rails/actionpack/test/controller/new_base/render_xml_test.rb +12 -0
- data/vendor/rails/actionpack/test/controller/output_escaping_test.rb +17 -0
- data/vendor/rails/actionpack/test/controller/parameter_encoding_test.rb +52 -0
- data/vendor/rails/actionpack/test/controller/parameters/accessors_test.rb +324 -0
- data/vendor/rails/actionpack/test/controller/parameters/always_permitted_parameters_test.rb +30 -0
- data/vendor/rails/actionpack/test/controller/parameters/dup_test.rb +67 -0
- data/vendor/rails/actionpack/test/controller/parameters/log_on_unpermitted_params_test.rb +70 -0
- data/vendor/rails/actionpack/test/controller/parameters/multi_parameter_attributes_test.rb +39 -0
- data/vendor/rails/actionpack/test/controller/parameters/mutators_test.rb +122 -0
- data/vendor/rails/actionpack/test/controller/parameters/nested_parameters_permit_test.rb +184 -0
- data/vendor/rails/actionpack/test/controller/parameters/parameters_permit_test.rb +516 -0
- data/vendor/rails/actionpack/test/controller/parameters/raise_on_unpermitted_params_test.rb +33 -0
- data/vendor/rails/actionpack/test/controller/parameters/serialization_test.rb +55 -0
- data/vendor/rails/actionpack/test/controller/params_wrapper_test.rb +422 -0
- data/vendor/rails/actionpack/test/controller/permitted_params_test.rb +27 -0
- data/vendor/rails/actionpack/test/controller/redirect_test.rb +395 -0
- data/vendor/rails/actionpack/test/controller/render_js_test.rb +36 -0
- data/vendor/rails/actionpack/test/controller/render_json_test.rb +137 -0
- data/vendor/rails/actionpack/test/controller/render_test.rb +843 -0
- data/vendor/rails/actionpack/test/controller/render_xml_test.rb +102 -0
- data/vendor/rails/actionpack/test/controller/renderer_test.rb +136 -0
- data/vendor/rails/actionpack/test/controller/renderers_test.rb +91 -0
- data/vendor/rails/actionpack/test/controller/request/test_request_test.rb +42 -0
- data/vendor/rails/actionpack/test/controller/request_forgery_protection_test.rb +1013 -0
- data/vendor/rails/actionpack/test/controller/required_params_test.rb +100 -0
- data/vendor/rails/actionpack/test/controller/rescue_test.rb +364 -0
- data/vendor/rails/actionpack/test/controller/resources_test.rb +1369 -0
- data/vendor/rails/actionpack/test/controller/routing_test.rb +2108 -0
- data/vendor/rails/actionpack/test/controller/runner_test.rb +24 -0
- data/vendor/rails/actionpack/test/controller/send_file_test.rb +259 -0
- data/vendor/rails/actionpack/test/controller/show_exceptions_test.rb +114 -0
- data/vendor/rails/actionpack/test/controller/streaming_test.rb +28 -0
- data/vendor/rails/actionpack/test/controller/test_case_test.rb +1157 -0
- data/vendor/rails/actionpack/test/controller/url_for_integration_test.rb +192 -0
- data/vendor/rails/actionpack/test/controller/url_for_test.rb +519 -0
- data/vendor/rails/actionpack/test/controller/url_rewriter_test.rb +92 -0
- data/vendor/rails/actionpack/test/controller/webservice_test.rb +135 -0
- data/vendor/rails/actionpack/test/dispatch/callbacks_test.rb +47 -0
- data/vendor/rails/actionpack/test/dispatch/content_security_policy_test.rb +525 -0
- data/vendor/rails/actionpack/test/dispatch/cookies_test.rb +1345 -0
- data/vendor/rails/actionpack/test/dispatch/debug_exceptions_test.rb +502 -0
- data/vendor/rails/actionpack/test/dispatch/debug_locks_test.rb +38 -0
- data/vendor/rails/actionpack/test/dispatch/exception_wrapper_test.rb +120 -0
- data/vendor/rails/actionpack/test/dispatch/executor_test.rb +136 -0
- data/vendor/rails/actionpack/test/dispatch/header_test.rb +169 -0
- data/vendor/rails/actionpack/test/dispatch/live_response_test.rb +98 -0
- data/vendor/rails/actionpack/test/dispatch/mapper_test.rb +210 -0
- data/vendor/rails/actionpack/test/dispatch/middleware_stack_test.rb +115 -0
- data/vendor/rails/actionpack/test/dispatch/mime_type_test.rb +187 -0
- data/vendor/rails/actionpack/test/dispatch/mount_test.rb +95 -0
- data/vendor/rails/actionpack/test/dispatch/prefix_generation_test.rb +463 -0
- data/vendor/rails/actionpack/test/dispatch/rack_cache_test.rb +23 -0
- data/vendor/rails/actionpack/test/dispatch/reloader_test.rb +167 -0
- data/vendor/rails/actionpack/test/dispatch/request/json_params_parsing_test.rb +207 -0
- data/vendor/rails/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +202 -0
- data/vendor/rails/actionpack/test/dispatch/request/query_string_parsing_test.rb +176 -0
- data/vendor/rails/actionpack/test/dispatch/request/session_test.rb +165 -0
- data/vendor/rails/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +181 -0
- data/vendor/rails/actionpack/test/dispatch/request_id_test.rb +75 -0
- data/vendor/rails/actionpack/test/dispatch/request_test.rb +1307 -0
- data/vendor/rails/actionpack/test/dispatch/response_test.rb +542 -0
- data/vendor/rails/actionpack/test/dispatch/routing/concerns_test.rb +124 -0
- data/vendor/rails/actionpack/test/dispatch/routing/custom_url_helpers_test.rb +333 -0
- data/vendor/rails/actionpack/test/dispatch/routing/inspector_test.rb +425 -0
- data/vendor/rails/actionpack/test/dispatch/routing/ipv6_redirect_test.rb +46 -0
- data/vendor/rails/actionpack/test/dispatch/routing/route_set_test.rb +166 -0
- data/vendor/rails/actionpack/test/dispatch/routing_assertions_test.rb +209 -0
- data/vendor/rails/actionpack/test/dispatch/routing_test.rb +5112 -0
- data/vendor/rails/actionpack/test/dispatch/runner_test.rb +19 -0
- data/vendor/rails/actionpack/test/dispatch/session/abstract_store_test.rb +58 -0
- data/vendor/rails/actionpack/test/dispatch/session/cache_store_test.rb +183 -0
- data/vendor/rails/actionpack/test/dispatch/session/cookie_store_test.rb +417 -0
- data/vendor/rails/actionpack/test/dispatch/session/mem_cache_store_test.rb +205 -0
- data/vendor/rails/actionpack/test/dispatch/session/test_session_test.rb +65 -0
- data/vendor/rails/actionpack/test/dispatch/show_exceptions_test.rb +138 -0
- data/vendor/rails/actionpack/test/dispatch/ssl_test.rb +228 -0
- data/vendor/rails/actionpack/test/dispatch/static_test.rb +318 -0
- data/vendor/rails/actionpack/test/dispatch/system_testing/driver_test.rb +54 -0
- data/vendor/rails/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb +81 -0
- data/vendor/rails/actionpack/test/dispatch/system_testing/server_test.rb +32 -0
- data/vendor/rails/actionpack/test/dispatch/system_testing/system_test_case_test.rb +84 -0
- data/vendor/rails/actionpack/test/dispatch/test_request_test.rb +131 -0
- data/vendor/rails/actionpack/test/dispatch/test_response_test.rb +37 -0
- data/vendor/rails/actionpack/test/dispatch/uploaded_file_test.rb +113 -0
- data/vendor/rails/actionpack/test/dispatch/url_generation_test.rb +141 -0
- data/vendor/rails/actionpack/test/fixtures/_top_level_partial_only.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/alternate_helpers/foo_helper.rb +5 -0
- data/vendor/rails/actionpack/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/collection_cache/index.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/company.rb +11 -0
- data/vendor/rails/actionpack/test/fixtures/customers/_commented_customer.html.erb +5 -0
- data/vendor/rails/actionpack/test/fixtures/customers/_customer.html.erb +4 -0
- data/vendor/rails/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/_formatted_partial.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/_partial.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/formatted_fragment_cached_with_variant.html+phone.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/fragment_cached.html.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/fragment_cached_with_options.html.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/fragment_cached_without_digest.html.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/vendor/rails/actionpack/test/fixtures/functional_caching/xml_fragment_cached_with_html_partial.xml.builder +5 -0
- data/vendor/rails/actionpack/test/fixtures/helpers/abc_helper.rb +5 -0
- data/vendor/rails/actionpack/test/fixtures/helpers/fun/games_helper.rb +7 -0
- data/vendor/rails/actionpack/test/fixtures/helpers/fun/pdf_helper.rb +7 -0
- data/vendor/rails/actionpack/test/fixtures/helpers/just_me_helper.rb +5 -0
- data/vendor/rails/actionpack/test/fixtures/helpers/me_too_helper.rb +5 -0
- data/vendor/rails/actionpack/test/fixtures/helpers1_pack/pack1_helper.rb +7 -0
- data/vendor/rails/actionpack/test/fixtures/helpers2_pack/pack2_helper.rb +7 -0
- data/vendor/rails/actionpack/test/fixtures/helpers_typo/admin/users_helper.rb +6 -0
- data/vendor/rails/actionpack/test/fixtures/implicit_render_test/empty_action_with_mobile_variant.html+mobile.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/implicit_render_test/empty_action_with_template.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/_customers.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/block_with_layout.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/builder.builder +3 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/partial_with_layout.erb +3 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/standard.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/talk_from_action.erb +2 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/with_html_partial.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/xhr.html.erb +2 -0
- data/vendor/rails/actionpack/test/fixtures/layouts/yield.erb +2 -0
- data/vendor/rails/actionpack/test/fixtures/load_me.rb +4 -0
- data/vendor/rails/actionpack/test/fixtures/localized/hello_world.de.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/localized/hello_world.en.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/localized/hello_world.it.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/binary_file +0 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/boundary_problem_file +10 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/bracketed_param +5 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/bracketed_utf8_param +5 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/empty +10 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/hello.txt +1 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/large_text_file +10 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/mixed_files +0 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/none +9 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/ruby_on_rails.jpg +0 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/single_parameter +5 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/single_utf8_param +5 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/text_file +10 -0
- data/vendor/rails/actionpack/test/fixtures/multipart/utf8_filename +10 -0
- data/vendor/rails/actionpack/test/fixtures/namespaced/implicit_render_test/hello_world.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/old_content_type/render_default_content_types_for_respond_to.xml.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/old_content_type/render_default_for_builder.builder +1 -0
- data/vendor/rails/actionpack/test/fixtures/old_content_type/render_default_for_erb.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/post/index.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/400.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/404.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/500.da.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/500.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/bar.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/bar/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo/bar.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo/baz.css +3 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo/other-index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo//343/201/223/343/202/223/343/201/253/343/201/241/343/201/257.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo//343/201/225/343/202/210/343/201/206/343/201/252/343/202/211.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/foo//343/201/225/343/202/210/343/201/206/343/201/252/343/202/211.html.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures/public/gzip/application-a71b3024f80aea3181c09774ca17e712.js +4 -0
- data/vendor/rails/actionpack/test/fixtures/public/gzip/application-a71b3024f80aea3181c09774ca17e712.js.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures/public/gzip/foo.zoo +4 -0
- data/vendor/rails/actionpack/test/fixtures/public/gzip/foo.zoo.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures/public/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/other-index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/all_types_with_layout.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/using_defaults.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/using_defaults.xml.builder +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/using_defaults_with_all.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/variant_any_implicit_render.html+phablet.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/variant_any_implicit_render.html+tablet.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/variant_inline_syntax_without_block.html+phone.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/variant_plus_none_for_format.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/respond_to/variant_with_implicit_template_rendering.html+mobile.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/ruby_template.ruby +2 -0
- data/vendor/rails/actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb +12 -0
- data/vendor/rails/actionpack/test/fixtures/shared.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/star_star_mime/index.js.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/_partial.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/_partial.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/_partial.js.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/dot.directory/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/hello/hello.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/hello_world.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/hello_world_with_partial.html.erb +2 -0
- data/vendor/rails/actionpack/test/fixtures/test/hello_xml_world.builder +11 -0
- data/vendor/rails/actionpack/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/vendor/rails/actionpack/test/fixtures/test/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/render_file_with_locals.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures/test/with_implicit_template.erb +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/bar.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/bar/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo/bar.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo/baz.css +3 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo/other-index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo//343/201/223/343/202/223/343/201/253/343/201/241/343/201/257.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo//343/201/225/343/202/210/343/201/206/343/201/252/343/202/211.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/foo//343/201/225/343/202/210/343/201/206/343/201/252/343/202/211.html.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/gzip/application-a71b3024f80aea3181c09774ca17e712.js +4 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/gzip/application-a71b3024f80aea3181c09774ca17e712.js.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/gzip/foo.zoo +4 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/gzip/foo.zoo.gz +0 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/index.html +1 -0
- data/vendor/rails/actionpack/test/fixtures//345/205/254/345/205/261/other-index.html +1 -0
- data/vendor/rails/actionpack/test/journey/gtg/builder_test.rb +81 -0
- data/vendor/rails/actionpack/test/journey/gtg/transition_table_test.rb +125 -0
- data/vendor/rails/actionpack/test/journey/nfa/simulator_test.rb +100 -0
- data/vendor/rails/actionpack/test/journey/nfa/transition_table_test.rb +74 -0
- data/vendor/rails/actionpack/test/journey/nodes/symbol_test.rb +19 -0
- data/vendor/rails/actionpack/test/journey/path/pattern_test.rb +286 -0
- data/vendor/rails/actionpack/test/journey/route/definition/parser_test.rb +112 -0
- data/vendor/rails/actionpack/test/journey/route/definition/scanner_test.rb +71 -0
- data/vendor/rails/actionpack/test/journey/route_test.rb +113 -0
- data/vendor/rails/actionpack/test/journey/router/utils_test.rb +48 -0
- data/vendor/rails/actionpack/test/journey/router_test.rb +544 -0
- data/vendor/rails/actionpack/test/journey/routes_test.rb +62 -0
- data/vendor/rails/actionpack/test/lib/controller/fake_controllers.rb +37 -0
- data/vendor/rails/actionpack/test/lib/controller/fake_models.rb +79 -0
- data/vendor/rails/actionpack/test/routing/helper_test.rb +33 -0
- data/vendor/rails/actionview/CHANGELOG.md +122 -0
- data/vendor/rails/actionview/MIT-LICENSE +21 -0
- data/vendor/rails/actionview/README.rdoc +38 -0
- data/vendor/rails/actionview/RUNNING_UJS_TESTS.rdoc +8 -0
- data/vendor/rails/actionview/RUNNING_UNIT_TESTS.rdoc +26 -0
- data/vendor/rails/actionview/Rakefile +136 -0
- data/vendor/rails/actionview/actionview.gemspec +38 -0
- data/vendor/rails/actionview/app/assets/javascripts/MIT-LICENSE +20 -0
- data/vendor/rails/actionview/app/assets/javascripts/README.md +55 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs.coffee +39 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/BANNER.js +5 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee +26 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/disable.coffee +82 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee +34 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee +90 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/start.coffee +71 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee +97 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csp.coffee +4 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee +25 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee +35 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee +68 -0
- data/vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee +36 -0
- data/vendor/rails/actionview/bin/test +5 -0
- data/vendor/rails/actionview/blade.yml +11 -0
- data/vendor/rails/actionview/coffeelint.json +135 -0
- data/vendor/rails/actionview/lib/action_view.rb +97 -0
- data/vendor/rails/actionview/lib/action_view/base.rb +215 -0
- data/vendor/rails/actionview/lib/action_view/buffers.rb +52 -0
- data/vendor/rails/actionview/lib/action_view/context.rb +36 -0
- data/vendor/rails/actionview/lib/action_view/dependency_tracker.rb +175 -0
- data/vendor/rails/actionview/lib/action_view/digestor.rb +136 -0
- data/vendor/rails/actionview/lib/action_view/flows.rb +76 -0
- data/vendor/rails/actionview/lib/action_view/gem_version.rb +17 -0
- data/vendor/rails/actionview/lib/action_view/helpers.rb +68 -0
- data/vendor/rails/actionview/lib/action_view/helpers/active_model_helper.rb +55 -0
- data/vendor/rails/actionview/lib/action_view/helpers/asset_tag_helper.rb +511 -0
- data/vendor/rails/actionview/lib/action_view/helpers/asset_url_helper.rb +469 -0
- data/vendor/rails/actionview/lib/action_view/helpers/atom_feed_helper.rb +205 -0
- data/vendor/rails/actionview/lib/action_view/helpers/cache_helper.rb +263 -0
- data/vendor/rails/actionview/lib/action_view/helpers/capture_helper.rb +212 -0
- data/vendor/rails/actionview/lib/action_view/helpers/controller_helper.rb +36 -0
- data/vendor/rails/actionview/lib/action_view/helpers/csp_helper.rb +24 -0
- data/vendor/rails/actionview/lib/action_view/helpers/csrf_helper.rb +35 -0
- data/vendor/rails/actionview/lib/action_view/helpers/date_helper.rb +1156 -0
- data/vendor/rails/actionview/lib/action_view/helpers/debug_helper.rb +36 -0
- data/vendor/rails/actionview/lib/action_view/helpers/form_helper.rb +2337 -0
- data/vendor/rails/actionview/lib/action_view/helpers/form_options_helper.rb +887 -0
- data/vendor/rails/actionview/lib/action_view/helpers/form_tag_helper.rb +917 -0
- data/vendor/rails/actionview/lib/action_view/helpers/javascript_helper.rb +94 -0
- data/vendor/rails/actionview/lib/action_view/helpers/number_helper.rb +451 -0
- data/vendor/rails/actionview/lib/action_view/helpers/output_safety_helper.rb +70 -0
- data/vendor/rails/actionview/lib/action_view/helpers/record_tag_helper.rb +23 -0
- data/vendor/rails/actionview/lib/action_view/helpers/rendering_helper.rb +99 -0
- data/vendor/rails/actionview/lib/action_view/helpers/sanitize_helper.rb +177 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tag_helper.rb +313 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags.rb +44 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/base.rb +192 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/check_box.rb +66 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/checkable.rb +18 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +36 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/collection_helpers.rb +119 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/collection_select.rb +30 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/color_field.rb +27 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/date_field.rb +15 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/date_select.rb +74 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/datetime_field.rb +32 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/datetime_local_field.rb +21 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/datetime_select.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/email_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/file_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/hidden_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/label.rb +81 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/month_field.rb +15 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/number_field.rb +20 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/password_field.rb +14 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/placeholderable.rb +24 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/radio_button.rb +33 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/range_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/search_field.rb +27 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/select.rb +43 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/tel_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/text_area.rb +24 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/text_field.rb +34 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/time_field.rb +15 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/time_select.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/translator.rb +44 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/url_field.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/helpers/tags/week_field.rb +15 -0
- data/vendor/rails/actionview/lib/action_view/helpers/text_helper.rb +486 -0
- data/vendor/rails/actionview/lib/action_view/helpers/translation_helper.rb +141 -0
- data/vendor/rails/actionview/lib/action_view/helpers/url_helper.rb +676 -0
- data/vendor/rails/actionview/lib/action_view/layouts.rb +433 -0
- data/vendor/rails/actionview/lib/action_view/locale/en.yml +56 -0
- data/vendor/rails/actionview/lib/action_view/log_subscriber.rb +96 -0
- data/vendor/rails/actionview/lib/action_view/lookup_context.rb +274 -0
- data/vendor/rails/actionview/lib/action_view/model_naming.rb +14 -0
- data/vendor/rails/actionview/lib/action_view/path_set.rb +100 -0
- data/vendor/rails/actionview/lib/action_view/railtie.rb +82 -0
- data/vendor/rails/actionview/lib/action_view/record_identifier.rb +112 -0
- data/vendor/rails/actionview/lib/action_view/renderer/abstract_renderer.rb +55 -0
- data/vendor/rails/actionview/lib/action_view/renderer/partial_renderer.rb +552 -0
- data/vendor/rails/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb +57 -0
- data/vendor/rails/actionview/lib/action_view/renderer/renderer.rb +56 -0
- data/vendor/rails/actionview/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
- data/vendor/rails/actionview/lib/action_view/renderer/template_renderer.rb +102 -0
- data/vendor/rails/actionview/lib/action_view/rendering.rb +151 -0
- data/vendor/rails/actionview/lib/action_view/routing_url_for.rb +145 -0
- data/vendor/rails/actionview/lib/action_view/tasks/cache_digests.rake +25 -0
- data/vendor/rails/actionview/lib/action_view/template.rb +361 -0
- data/vendor/rails/actionview/lib/action_view/template/error.rb +141 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers.rb +66 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers/builder.rb +25 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers/erb.rb +74 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers/erb/erubi.rb +83 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers/html.rb +11 -0
- data/vendor/rails/actionview/lib/action_view/template/handlers/raw.rb +11 -0
- data/vendor/rails/actionview/lib/action_view/template/html.rb +34 -0
- data/vendor/rails/actionview/lib/action_view/template/resolver.rb +391 -0
- data/vendor/rails/actionview/lib/action_view/template/text.rb +33 -0
- data/vendor/rails/actionview/lib/action_view/template/types.rb +57 -0
- data/vendor/rails/actionview/lib/action_view/test_case.rb +300 -0
- data/vendor/rails/actionview/lib/action_view/testing/resolvers.rb +54 -0
- data/vendor/rails/actionview/lib/action_view/version.rb +10 -0
- data/vendor/rails/actionview/lib/action_view/view_paths.rb +105 -0
- data/vendor/rails/actionview/package.json +36 -0
- data/vendor/rails/actionview/test/abstract_unit.rb +236 -0
- data/vendor/rails/actionview/test/actionpack/abstract/abstract_controller_test.rb +292 -0
- data/vendor/rails/actionview/test/actionpack/abstract/helper_test.rb +128 -0
- data/vendor/rails/actionview/test/actionpack/abstract/layouts_test.rb +568 -0
- data/vendor/rails/actionview/test/actionpack/abstract/render_test.rb +103 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/abstract_controller/testing/me3/formatted.html.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/abstract_controller/testing/me3/index.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/abstract_controller/testing/me4/index.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/action_with_ivars.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/helper_test.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/index.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/layouts/abstract_controller/testing/me4.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/layouts/application.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/abstract/views/naked_render.erb +1 -0
- data/vendor/rails/actionview/test/actionpack/controller/capture_test.rb +83 -0
- data/vendor/rails/actionview/test/actionpack/controller/layout_test.rb +270 -0
- data/vendor/rails/actionview/test/actionpack/controller/render_test.rb +1294 -0
- data/vendor/rails/actionview/test/actionpack/controller/view_paths_test.rb +174 -0
- data/vendor/rails/actionview/test/active_record_unit.rb +92 -0
- data/vendor/rails/actionview/test/activerecord/controller_runtime_test.rb +95 -0
- data/vendor/rails/actionview/test/activerecord/debug_helper_test.rb +19 -0
- data/vendor/rails/actionview/test/activerecord/form_helper_activerecord_test.rb +90 -0
- data/vendor/rails/actionview/test/activerecord/polymorphic_routes_test.rb +780 -0
- data/vendor/rails/actionview/test/activerecord/relation_cache_test.rb +23 -0
- data/vendor/rails/actionview/test/activerecord/render_partial_with_record_identification_test.rb +188 -0
- data/vendor/rails/actionview/test/fixtures/_top_level_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/_top_level_partial_only.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/bad_customers/_bad_customer.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/customers/_customer.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/fun/games/_form.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/fun/games/hello_world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/good_customers/_good_customer.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/hello.html +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/alt/layouts/alt.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/controller_name_space/nested.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/item.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/layout_test.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/symlinked/symlinked_layout.erb +5 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/layouts/third_party_template_library.mab +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/views/goodbye.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layout_tests/views/hello.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/_column.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/_customers.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/_partial_and_yield.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/_yield_only.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/_yield_with_params.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/block_with_layout.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/builder.builder +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/partial_with_layout.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/standard.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/standard.text.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/streaming.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/talk_from_action.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/with_html_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/xhr.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/yield.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/yield_with_render_inline_inside.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/layouts/yield_with_render_partial_inside.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/quiz/questions/_question.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/shared.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_changing_priority.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_changing_priority.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_counter.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_counter.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_counter_with_as.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_greeting.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_iteration.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_iteration_with_as.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_customer_with_var.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_directory/_partial_with_locales.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_first_json_partial.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_form.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_hash_greeting.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_hash_object.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_hello.builder +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_json_change_priority.json.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_labelling_form.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_layout_for_partial.html.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial.js.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_for_use_in_layout.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_html_erb.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_name_local_variable.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_only.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_only_html.html +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_partial_with_partial.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_person.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_raise_indentation.html.erb +13 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/_second_json_partial.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/action_talk_to_layout.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/calling_partial_with_layout.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/capturing.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/change_priority.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/content_for.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/content_for_concatenated.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/content_for_with_parameter.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/dot.directory/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/formatted_html_erb.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/formatted_xml_erb.builder +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/formatted_xml_erb.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/formatted_xml_erb.xml.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/greeting.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/greeting.xml.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello,world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello.builder +4 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello/hello.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_world_container.builder +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_world_from_rxml.builder +3 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_world_with_layout_false.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_world_with_partial.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hello_xml_world.builder +11 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/html_template.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/hyphen-ated.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/implicit_content_type.atom.builder +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/list.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/non_erb_block_content_for.builder +4 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/potential_conflicts.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/proper_block_detection.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_file_from_template.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_file_with_locals.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_file_with_locals_and_default.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_partial_inside_directory.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_to_string_test.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/render_two_partials.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/using_layout_around_block.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/with_html_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/with_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/with_partial.text.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/actionpack/test/with_xml_template.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/comments/empty.de.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/comments/empty.html+grid.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/comments/empty.html.builder +1 -0
- data/vendor/rails/actionview/test/fixtures/comments/empty.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/comments/empty.xml.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/companies.yml +24 -0
- data/vendor/rails/actionview/test/fixtures/company.rb +11 -0
- data/vendor/rails/actionview/test/fixtures/custom_pattern/another.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/custom_pattern/html/another.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/custom_pattern/html/path.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/customers/_customer.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/customers/_customer.xml.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/db_definitions/sqlite.sql +49 -0
- data/vendor/rails/actionview/test/fixtures/developer.rb +8 -0
- data/vendor/rails/actionview/test/fixtures/developers.yml +21 -0
- data/vendor/rails/actionview/test/fixtures/developers/_developer.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/developers_projects.yml +13 -0
- data/vendor/rails/actionview/test/fixtures/digestor/api/comments/_comment.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/api/comments/_comments.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/comments/_comment.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/comments/_comments.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/comments/show.js.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/events/_completed.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/events/_event.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/events/index.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/level/_recursion.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/level/below/_header.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/level/below/index.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/level/recursion.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/_form.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/_header.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/_message.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/actions/_move.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/edit.html.erb +5 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/index.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/new.html+iphone.erb +15 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/peek.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/show.html.erb +14 -0
- data/vendor/rails/actionview/test/fixtures/digestor/messages/thread.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/fun/games/_game.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/fun/games/hello_world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/games/_game.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/helpers/abc_helper.rb +5 -0
- data/vendor/rails/actionview/test/fixtures/helpers/helpery_test_helper.rb +7 -0
- data/vendor/rails/actionview/test/fixtures/helpers_missing/invalid_require_helper.rb +6 -0
- data/vendor/rails/actionview/test/fixtures/layout_tests/alt/hello.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/layouts/_column.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/_customers.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/layouts/_partial_and_yield.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/_yield_only.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/layouts/_yield_with_params.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/layouts/render_partial_html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/streaming.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/layouts/streaming_with_capture.erb +6 -0
- data/vendor/rails/actionview/test/fixtures/layouts/streaming_with_locale.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/yield.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/yield_with_render_inline_inside.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/layouts/yield_with_render_partial_inside.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/mascot.rb +5 -0
- data/vendor/rails/actionview/test/fixtures/mascots.yml +4 -0
- data/vendor/rails/actionview/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/override/test/hello_world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/plain_text.raw +1 -0
- data/vendor/rails/actionview/test/fixtures/plain_text_with_characters.raw +1 -0
- data/vendor/rails/actionview/test/fixtures/project.rb +9 -0
- data/vendor/rails/actionview/test/fixtures/projects.yml +7 -0
- data/vendor/rails/actionview/test/fixtures/projects/_project.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/public/elsewhere/cools.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/elsewhere/file.css +1 -0
- data/vendor/rails/actionview/test/fixtures/public/foo/baz.css +3 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/application.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/bank.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/common.javascript +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/controls.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/effects.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/prototype.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/robber.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/vendor/rails/actionview/test/fixtures/public/stylesheets/bank.css +1 -0
- data/vendor/rails/actionview/test/fixtures/public/stylesheets/random.styles +1 -0
- data/vendor/rails/actionview/test/fixtures/public/stylesheets/robber.css +1 -0
- data/vendor/rails/actionview/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/vendor/rails/actionview/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/vendor/rails/actionview/test/fixtures/replies.yml +15 -0
- data/vendor/rails/actionview/test/fixtures/replies/_reply.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/reply.rb +9 -0
- data/vendor/rails/actionview/test/fixtures/respond_to/using_defaults_with_all.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/ruby_template.ruby +2 -0
- data/vendor/rails/actionview/test/fixtures/shared.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_200.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_FooBar.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_a-in.html.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/test/_b_layout_for_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_b_layout_for_partial_with_object.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_b_layout_for_partial_with_object_counter.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_builder_tag_nested_in_content_tag.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_cached_customer.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_cached_customer_as.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_cached_nested_cached_customer.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_changing_priority.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_changing_priority.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_content_tag_nested_in_content_tag.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_counter.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_customer.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_customer.mobile.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_customer_greeting.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_customer_with_var.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_directory/_partial_with_locales.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_first_json_partial.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_from_helper.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_json_change_priority.json.erb +0 -0
- data/vendor/rails/actionview/test/fixtures/test/_klass.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_label_with_block.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_layout_with_partial_and_yield.html.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_nested_cached_customer.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_object_inspector.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_one.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial.js.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_iteration_1.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_iteration_2.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_name_in_local_assigns.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_name_local_variable.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_only.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_shortcut_with_block_content.html.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_layout.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_layout_block_content.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_layout_block_partial.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_partial.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/_partial_with_variants.html+grid.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_partialhtml.html +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_raise.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_raise_indentation.html.erb +13 -0
- data/vendor/rails/actionview/test/fixtures/test/_second_json_partial.json.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_two.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_utf8_partial.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/_utf8_partial_magic.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/_/360/237/215/243.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/basic.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/change_priority.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/dont_pick_me +1 -0
- data/vendor/rails/actionview/test/fixtures/test/dot.directory/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/greeting.xml.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello.builder +4 -0
- data/vendor/rails/actionview/test/fixtures/test/hello/hello.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.erb~ +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.html+phone.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world.text+phone.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/hello_world_with_partial.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/html_template.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/layout_render_file.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/layout_render_object.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/list.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/vendor/rails/actionview/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/vendor/rails/actionview/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/vendor/rails/actionview/test/fixtures/test/malformed/malformed~ +1 -0
- data/vendor/rails/actionview/test/fixtures/test/nested_layout.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/nested_streaming.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/nil_return.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/one.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_inspect_local_assigns.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_instance_variable.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_unicode_local.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_with_ivar.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_with_locals.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_with_locals_and_default.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_file_with_ruby_keyword_locals.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_partial_inside_directory.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/render_two_partials.html.erb +2 -0
- data/vendor/rails/actionview/test/fixtures/test/streaming.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/streaming_buster.erb +3 -0
- data/vendor/rails/actionview/test/fixtures/test/streaming_with_locale.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/template.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/test/update_element_with_capture.erb +9 -0
- data/vendor/rails/actionview/test/fixtures/test/utf8.html.erb +4 -0
- data/vendor/rails/actionview/test/fixtures/test/utf8_magic.html.erb +5 -0
- data/vendor/rails/actionview/test/fixtures/test/utf8_magic_with_bare_partial.html.erb +5 -0
- data/vendor/rails/actionview/test/fixtures/topic.rb +5 -0
- data/vendor/rails/actionview/test/fixtures/topics.yml +22 -0
- data/vendor/rails/actionview/test/fixtures/topics/_topic.html.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/translations/templates/array.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/translations/templates/default.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/translations/templates/found.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/translations/templates/missing.erb +1 -0
- data/vendor/rails/actionview/test/fixtures/with_format.json.erb +1 -0
- data/vendor/rails/actionview/test/lib/controller/fake_models.rb +204 -0
- data/vendor/rails/actionview/test/template/active_model_helper_test.rb +172 -0
- data/vendor/rails/actionview/test/template/asset_tag_helper_test.rb +913 -0
- data/vendor/rails/actionview/test/template/atom_feed_helper_test.rb +375 -0
- data/vendor/rails/actionview/test/template/capture_helper_test.rb +228 -0
- data/vendor/rails/actionview/test/template/compiled_templates_test.rb +94 -0
- data/vendor/rails/actionview/test/template/controller_helper_test.rb +34 -0
- data/vendor/rails/actionview/test/template/date_helper_i18n_test.rb +166 -0
- data/vendor/rails/actionview/test/template/date_helper_test.rb +3642 -0
- data/vendor/rails/actionview/test/template/dependency_tracker_test.rb +195 -0
- data/vendor/rails/actionview/test/template/digestor_test.rb +389 -0
- data/vendor/rails/actionview/test/template/erb/form_for_test.rb +13 -0
- data/vendor/rails/actionview/test/template/erb/helper.rb +26 -0
- data/vendor/rails/actionview/test/template/erb/tag_helper_test.rb +32 -0
- data/vendor/rails/actionview/test/template/erb_util_test.rb +114 -0
- data/vendor/rails/actionview/test/template/form_collections_helper_test.rb +527 -0
- data/vendor/rails/actionview/test/template/form_helper/form_with_test.rb +2293 -0
- data/vendor/rails/actionview/test/template/form_helper_test.rb +3554 -0
- data/vendor/rails/actionview/test/template/form_options_helper_i18n_test.rb +30 -0
- data/vendor/rails/actionview/test/template/form_options_helper_test.rb +1452 -0
- data/vendor/rails/actionview/test/template/form_tag_helper_test.rb +785 -0
- data/vendor/rails/actionview/test/template/html_test.rb +19 -0
- data/vendor/rails/actionview/test/template/javascript_helper_test.rb +68 -0
- data/vendor/rails/actionview/test/template/log_subscriber_test.rb +224 -0
- data/vendor/rails/actionview/test/template/lookup_context_test.rb +289 -0
- data/vendor/rails/actionview/test/template/number_helper_test.rb +204 -0
- data/vendor/rails/actionview/test/template/output_safety_helper_test.rb +119 -0
- data/vendor/rails/actionview/test/template/partial_iteration_test.rb +35 -0
- data/vendor/rails/actionview/test/template/record_identifier_test.rb +93 -0
- data/vendor/rails/actionview/test/template/record_tag_helper_test.rb +33 -0
- data/vendor/rails/actionview/test/template/render_test.rb +725 -0
- data/vendor/rails/actionview/test/template/resolver_cache_test.rb +9 -0
- data/vendor/rails/actionview/test/template/resolver_patterns_test.rb +44 -0
- data/vendor/rails/actionview/test/template/sanitize_helper_test.rb +43 -0
- data/vendor/rails/actionview/test/template/streaming_render_test.rb +132 -0
- data/vendor/rails/actionview/test/template/tag_helper_test.rb +357 -0
- data/vendor/rails/actionview/test/template/template_error_test.rb +37 -0
- data/vendor/rails/actionview/test/template/template_test.rb +207 -0
- data/vendor/rails/actionview/test/template/test_case_test.rb +335 -0
- data/vendor/rails/actionview/test/template/test_test.rb +94 -0
- data/vendor/rails/actionview/test/template/testing/fixture_resolver_test.rb +20 -0
- data/vendor/rails/actionview/test/template/testing/null_resolver_test.rb +14 -0
- data/vendor/rails/actionview/test/template/text_helper_test.rb +535 -0
- data/vendor/rails/actionview/test/template/text_test.rb +25 -0
- data/vendor/rails/actionview/test/template/translation_helper_test.rb +238 -0
- data/vendor/rails/actionview/test/template/url_helper_test.rb +976 -0
- data/vendor/rails/actionview/test/ujs/config.ru +6 -0
- data/vendor/rails/actionview/test/ujs/public/test/call-ajax.js +26 -0
- data/vendor/rails/actionview/test/ujs/public/test/call-remote-callbacks.js +239 -0
- data/vendor/rails/actionview/test/ujs/public/test/call-remote.js +275 -0
- data/vendor/rails/actionview/test/ujs/public/test/csrf-refresh.js +24 -0
- data/vendor/rails/actionview/test/ujs/public/test/csrf-token.js +27 -0
- data/vendor/rails/actionview/test/ujs/public/test/data-confirm.js +316 -0
- data/vendor/rails/actionview/test/ujs/public/test/data-disable-with.js +394 -0
- data/vendor/rails/actionview/test/ujs/public/test/data-disable.js +322 -0
- data/vendor/rails/actionview/test/ujs/public/test/data-method.js +85 -0
- data/vendor/rails/actionview/test/ujs/public/test/data-remote.js +441 -0
- data/vendor/rails/actionview/test/ujs/public/test/override.js +56 -0
- data/vendor/rails/actionview/test/ujs/public/test/settings.js +118 -0
- data/vendor/rails/actionview/test/ujs/public/vendor/jquery-2.2.0.js +9831 -0
- data/vendor/rails/actionview/test/ujs/public/vendor/jquery.metadata.js +122 -0
- data/vendor/rails/actionview/test/ujs/public/vendor/qunit.css +237 -0
- data/vendor/rails/actionview/test/ujs/public/vendor/qunit.js +2288 -0
- data/vendor/rails/actionview/test/ujs/server.rb +86 -0
- data/vendor/rails/actionview/test/ujs/views/layouts/application.html.erb +26 -0
- data/vendor/rails/actionview/test/ujs/views/tests/index.html.erb +11 -0
- data/vendor/rails/ci/qunit-selenium-runner.rb +16 -0
- data/vendor/rails/ci/travis.rb +187 -0
- data/vendor/rails/rails.gemspec +36 -0
- data/vendor/rails/version.rb +17 -0
- metadata +1030 -30
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
# = Action View Debug Helper
|
5
|
+
#
|
6
|
+
# Provides a set of methods for making it easier to debug Rails objects.
|
7
|
+
module Helpers #:nodoc:
|
8
|
+
module DebugHelper
|
9
|
+
include TagHelper
|
10
|
+
|
11
|
+
# Returns a YAML representation of +object+ wrapped with <pre> and </pre>.
|
12
|
+
# If the object cannot be converted to YAML using +to_yaml+, +inspect+ will be called instead.
|
13
|
+
# Useful for inspecting an object at the time of rendering.
|
14
|
+
#
|
15
|
+
# @user = User.new({ username: 'testing', password: 'xyz', age: 42})
|
16
|
+
# debug(@user)
|
17
|
+
# # =>
|
18
|
+
# <pre class='debug_dump'>--- !ruby/object:User
|
19
|
+
# attributes:
|
20
|
+
# updated_at:
|
21
|
+
# username: testing
|
22
|
+
# age: 42
|
23
|
+
# password: xyz
|
24
|
+
# created_at:
|
25
|
+
# </pre>
|
26
|
+
def debug(object)
|
27
|
+
Marshal.dump(object)
|
28
|
+
object = ERB::Util.html_escape(object.to_yaml)
|
29
|
+
content_tag(:pre, object, class: "debug_dump")
|
30
|
+
rescue # errors from Marshal or YAML
|
31
|
+
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
|
32
|
+
content_tag(:code, object.inspect, class: "debug_dump")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,2337 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "action_view/helpers/date_helper"
|
5
|
+
require "action_view/helpers/tag_helper"
|
6
|
+
require "action_view/helpers/form_tag_helper"
|
7
|
+
require "action_view/helpers/active_model_helper"
|
8
|
+
require "action_view/model_naming"
|
9
|
+
require "action_view/record_identifier"
|
10
|
+
require "active_support/core_ext/module/attribute_accessors"
|
11
|
+
require "active_support/core_ext/hash/slice"
|
12
|
+
require "active_support/core_ext/string/output_safety"
|
13
|
+
require "active_support/core_ext/string/inflections"
|
14
|
+
|
15
|
+
module ActionView
|
16
|
+
# = Action View Form Helpers
|
17
|
+
module Helpers #:nodoc:
|
18
|
+
# Form helpers are designed to make working with resources much easier
|
19
|
+
# compared to using vanilla HTML.
|
20
|
+
#
|
21
|
+
# Typically, a form designed to create or update a resource reflects the
|
22
|
+
# identity of the resource in several ways: (i) the URL that the form is
|
23
|
+
# sent to (the form element's +action+ attribute) should result in a request
|
24
|
+
# being routed to the appropriate controller action (with the appropriate <tt>:id</tt>
|
25
|
+
# parameter in the case of an existing resource), (ii) input fields should
|
26
|
+
# be named in such a way that in the controller their values appear in the
|
27
|
+
# appropriate places within the +params+ hash, and (iii) for an existing record,
|
28
|
+
# when the form is initially displayed, input fields corresponding to attributes
|
29
|
+
# of the resource should show the current values of those attributes.
|
30
|
+
#
|
31
|
+
# In Rails, this is usually achieved by creating the form using +form_for+ and
|
32
|
+
# a number of related helper methods. +form_for+ generates an appropriate <tt>form</tt>
|
33
|
+
# tag and yields a form builder object that knows the model the form is about.
|
34
|
+
# Input fields are created by calling methods defined on the form builder, which
|
35
|
+
# means they are able to generate the appropriate names and default values
|
36
|
+
# corresponding to the model attributes, as well as convenient IDs, etc.
|
37
|
+
# Conventions in the generated field names allow controllers to receive form data
|
38
|
+
# nicely structured in +params+ with no effort on your side.
|
39
|
+
#
|
40
|
+
# For example, to create a new person you typically set up a new instance of
|
41
|
+
# +Person+ in the <tt>PeopleController#new</tt> action, <tt>@person</tt>, and
|
42
|
+
# in the view template pass that object to +form_for+:
|
43
|
+
#
|
44
|
+
# <%= form_for @person do |f| %>
|
45
|
+
# <%= f.label :first_name %>:
|
46
|
+
# <%= f.text_field :first_name %><br />
|
47
|
+
#
|
48
|
+
# <%= f.label :last_name %>:
|
49
|
+
# <%= f.text_field :last_name %><br />
|
50
|
+
#
|
51
|
+
# <%= f.submit %>
|
52
|
+
# <% end %>
|
53
|
+
#
|
54
|
+
# The HTML generated for this would be (modulus formatting):
|
55
|
+
#
|
56
|
+
# <form action="/people" class="new_person" id="new_person" method="post">
|
57
|
+
# <input name="authenticity_token" type="hidden" value="NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=" />
|
58
|
+
# <label for="person_first_name">First name</label>:
|
59
|
+
# <input id="person_first_name" name="person[first_name]" type="text" /><br />
|
60
|
+
#
|
61
|
+
# <label for="person_last_name">Last name</label>:
|
62
|
+
# <input id="person_last_name" name="person[last_name]" type="text" /><br />
|
63
|
+
#
|
64
|
+
# <input name="commit" type="submit" value="Create Person" />
|
65
|
+
# </form>
|
66
|
+
#
|
67
|
+
# As you see, the HTML reflects knowledge about the resource in several spots,
|
68
|
+
# like the path the form should be submitted to, or the names of the input fields.
|
69
|
+
#
|
70
|
+
# In particular, thanks to the conventions followed in the generated field names, the
|
71
|
+
# controller gets a nested hash <tt>params[:person]</tt> with the person attributes
|
72
|
+
# set in the form. That hash is ready to be passed to <tt>Person.new</tt>:
|
73
|
+
#
|
74
|
+
# @person = Person.new(params[:person])
|
75
|
+
# if @person.save
|
76
|
+
# # success
|
77
|
+
# else
|
78
|
+
# # error handling
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# Interestingly, the exact same view code in the previous example can be used to edit
|
82
|
+
# a person. If <tt>@person</tt> is an existing record with name "John Smith" and ID 256,
|
83
|
+
# the code above as is would yield instead:
|
84
|
+
#
|
85
|
+
# <form action="/people/256" class="edit_person" id="edit_person_256" method="post">
|
86
|
+
# <input name="_method" type="hidden" value="patch" />
|
87
|
+
# <input name="authenticity_token" type="hidden" value="NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=" />
|
88
|
+
# <label for="person_first_name">First name</label>:
|
89
|
+
# <input id="person_first_name" name="person[first_name]" type="text" value="John" /><br />
|
90
|
+
#
|
91
|
+
# <label for="person_last_name">Last name</label>:
|
92
|
+
# <input id="person_last_name" name="person[last_name]" type="text" value="Smith" /><br />
|
93
|
+
#
|
94
|
+
# <input name="commit" type="submit" value="Update Person" />
|
95
|
+
# </form>
|
96
|
+
#
|
97
|
+
# Note that the endpoint, default values, and submit button label are tailored for <tt>@person</tt>.
|
98
|
+
# That works that way because the involved helpers know whether the resource is a new record or not,
|
99
|
+
# and generate HTML accordingly.
|
100
|
+
#
|
101
|
+
# The controller would receive the form data again in <tt>params[:person]</tt>, ready to be
|
102
|
+
# passed to <tt>Person#update</tt>:
|
103
|
+
#
|
104
|
+
# if @person.update(params[:person])
|
105
|
+
# # success
|
106
|
+
# else
|
107
|
+
# # error handling
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# That's how you typically work with resources.
|
111
|
+
module FormHelper
|
112
|
+
extend ActiveSupport::Concern
|
113
|
+
|
114
|
+
include FormTagHelper
|
115
|
+
include UrlHelper
|
116
|
+
include ModelNaming
|
117
|
+
include RecordIdentifier
|
118
|
+
|
119
|
+
attr_internal :default_form_builder
|
120
|
+
|
121
|
+
# Creates a form that allows the user to create or update the attributes
|
122
|
+
# of a specific model object.
|
123
|
+
#
|
124
|
+
# The method can be used in several slightly different ways, depending on
|
125
|
+
# how much you wish to rely on Rails to infer automatically from the model
|
126
|
+
# how the form should be constructed. For a generic model object, a form
|
127
|
+
# can be created by passing +form_for+ a string or symbol representing
|
128
|
+
# the object we are concerned with:
|
129
|
+
#
|
130
|
+
# <%= form_for :person do |f| %>
|
131
|
+
# First name: <%= f.text_field :first_name %><br />
|
132
|
+
# Last name : <%= f.text_field :last_name %><br />
|
133
|
+
# Biography : <%= f.text_area :biography %><br />
|
134
|
+
# Admin? : <%= f.check_box :admin %><br />
|
135
|
+
# <%= f.submit %>
|
136
|
+
# <% end %>
|
137
|
+
#
|
138
|
+
# The variable +f+ yielded to the block is a FormBuilder object that
|
139
|
+
# incorporates the knowledge about the model object represented by
|
140
|
+
# <tt>:person</tt> passed to +form_for+. Methods defined on the FormBuilder
|
141
|
+
# are used to generate fields bound to this model. Thus, for example,
|
142
|
+
#
|
143
|
+
# <%= f.text_field :first_name %>
|
144
|
+
#
|
145
|
+
# will get expanded to
|
146
|
+
#
|
147
|
+
# <%= text_field :person, :first_name %>
|
148
|
+
#
|
149
|
+
# which results in an HTML <tt><input></tt> tag whose +name+ attribute is
|
150
|
+
# <tt>person[first_name]</tt>. This means that when the form is submitted,
|
151
|
+
# the value entered by the user will be available in the controller as
|
152
|
+
# <tt>params[:person][:first_name]</tt>.
|
153
|
+
#
|
154
|
+
# For fields generated in this way using the FormBuilder,
|
155
|
+
# if <tt>:person</tt> also happens to be the name of an instance variable
|
156
|
+
# <tt>@person</tt>, the default value of the field shown when the form is
|
157
|
+
# initially displayed (e.g. in the situation where you are editing an
|
158
|
+
# existing record) will be the value of the corresponding attribute of
|
159
|
+
# <tt>@person</tt>.
|
160
|
+
#
|
161
|
+
# The rightmost argument to +form_for+ is an
|
162
|
+
# optional hash of options -
|
163
|
+
#
|
164
|
+
# * <tt>:url</tt> - The URL the form is to be submitted to. This may be
|
165
|
+
# represented in the same way as values passed to +url_for+ or +link_to+.
|
166
|
+
# So for example you may use a named route directly. When the model is
|
167
|
+
# represented by a string or symbol, as in the example above, if the
|
168
|
+
# <tt>:url</tt> option is not specified, by default the form will be
|
169
|
+
# sent back to the current URL (We will describe below an alternative
|
170
|
+
# resource-oriented usage of +form_for+ in which the URL does not need
|
171
|
+
# to be specified explicitly).
|
172
|
+
# * <tt>:namespace</tt> - A namespace for your form to ensure uniqueness of
|
173
|
+
# id attributes on form elements. The namespace attribute will be prefixed
|
174
|
+
# with underscore on the generated HTML id.
|
175
|
+
# * <tt>:method</tt> - The method to use when submitting the form, usually
|
176
|
+
# either "get" or "post". If "patch", "put", "delete", or another verb
|
177
|
+
# is used, a hidden input with name <tt>_method</tt> is added to
|
178
|
+
# simulate the verb over post.
|
179
|
+
# * <tt>:authenticity_token</tt> - Authenticity token to use in the form.
|
180
|
+
# Use only if you need to pass custom authenticity token string, or to
|
181
|
+
# not add authenticity_token field at all (by passing <tt>false</tt>).
|
182
|
+
# Remote forms may omit the embedded authenticity token by setting
|
183
|
+
# <tt>config.action_view.embed_authenticity_token_in_remote_forms = false</tt>.
|
184
|
+
# This is helpful when you're fragment-caching the form. Remote forms
|
185
|
+
# get the authenticity token from the <tt>meta</tt> tag, so embedding is
|
186
|
+
# unnecessary unless you support browsers without JavaScript.
|
187
|
+
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive
|
188
|
+
# JavaScript drivers to control the submit behavior. By default this
|
189
|
+
# behavior is an ajax submit.
|
190
|
+
# * <tt>:enforce_utf8</tt> - If set to false, a hidden input with name
|
191
|
+
# utf8 is not output.
|
192
|
+
# * <tt>:html</tt> - Optional HTML attributes for the form tag.
|
193
|
+
#
|
194
|
+
# Also note that +form_for+ doesn't create an exclusive scope. It's still
|
195
|
+
# possible to use both the stand-alone FormHelper methods and methods
|
196
|
+
# from FormTagHelper. For example:
|
197
|
+
#
|
198
|
+
# <%= form_for :person do |f| %>
|
199
|
+
# First name: <%= f.text_field :first_name %>
|
200
|
+
# Last name : <%= f.text_field :last_name %>
|
201
|
+
# Biography : <%= text_area :person, :biography %>
|
202
|
+
# Admin? : <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
|
203
|
+
# <%= f.submit %>
|
204
|
+
# <% end %>
|
205
|
+
#
|
206
|
+
# This also works for the methods in FormOptionsHelper and DateHelper that
|
207
|
+
# are designed to work with an object as base, like
|
208
|
+
# FormOptionsHelper#collection_select and DateHelper#datetime_select.
|
209
|
+
#
|
210
|
+
# === #form_for with a model object
|
211
|
+
#
|
212
|
+
# In the examples above, the object to be created or edited was
|
213
|
+
# represented by a symbol passed to +form_for+, and we noted that
|
214
|
+
# a string can also be used equivalently. It is also possible, however,
|
215
|
+
# to pass a model object itself to +form_for+. For example, if <tt>@post</tt>
|
216
|
+
# is an existing record you wish to edit, you can create the form using
|
217
|
+
#
|
218
|
+
# <%= form_for @post do |f| %>
|
219
|
+
# ...
|
220
|
+
# <% end %>
|
221
|
+
#
|
222
|
+
# This behaves in almost the same way as outlined previously, with a
|
223
|
+
# couple of small exceptions. First, the prefix used to name the input
|
224
|
+
# elements within the form (hence the key that denotes them in the +params+
|
225
|
+
# hash) is actually derived from the object's _class_, e.g. <tt>params[:post]</tt>
|
226
|
+
# if the object's class is +Post+. However, this can be overwritten using
|
227
|
+
# the <tt>:as</tt> option, e.g. -
|
228
|
+
#
|
229
|
+
# <%= form_for(@person, as: :client) do |f| %>
|
230
|
+
# ...
|
231
|
+
# <% end %>
|
232
|
+
#
|
233
|
+
# would result in <tt>params[:client]</tt>.
|
234
|
+
#
|
235
|
+
# Secondly, the field values shown when the form is initially displayed
|
236
|
+
# are taken from the attributes of the object passed to +form_for+,
|
237
|
+
# regardless of whether the object is an instance
|
238
|
+
# variable. So, for example, if we had a _local_ variable +post+
|
239
|
+
# representing an existing record,
|
240
|
+
#
|
241
|
+
# <%= form_for post do |f| %>
|
242
|
+
# ...
|
243
|
+
# <% end %>
|
244
|
+
#
|
245
|
+
# would produce a form with fields whose initial state reflect the current
|
246
|
+
# values of the attributes of +post+.
|
247
|
+
#
|
248
|
+
# === Resource-oriented style
|
249
|
+
#
|
250
|
+
# In the examples just shown, although not indicated explicitly, we still
|
251
|
+
# need to use the <tt>:url</tt> option in order to specify where the
|
252
|
+
# form is going to be sent. However, further simplification is possible
|
253
|
+
# if the record passed to +form_for+ is a _resource_, i.e. it corresponds
|
254
|
+
# to a set of RESTful routes, e.g. defined using the +resources+ method
|
255
|
+
# in <tt>config/routes.rb</tt>. In this case Rails will simply infer the
|
256
|
+
# appropriate URL from the record itself. For example,
|
257
|
+
#
|
258
|
+
# <%= form_for @post do |f| %>
|
259
|
+
# ...
|
260
|
+
# <% end %>
|
261
|
+
#
|
262
|
+
# is then equivalent to something like:
|
263
|
+
#
|
264
|
+
# <%= form_for @post, as: :post, url: post_path(@post), method: :patch, html: { class: "edit_post", id: "edit_post_45" } do |f| %>
|
265
|
+
# ...
|
266
|
+
# <% end %>
|
267
|
+
#
|
268
|
+
# And for a new record
|
269
|
+
#
|
270
|
+
# <%= form_for(Post.new) do |f| %>
|
271
|
+
# ...
|
272
|
+
# <% end %>
|
273
|
+
#
|
274
|
+
# is equivalent to something like:
|
275
|
+
#
|
276
|
+
# <%= form_for @post, as: :post, url: posts_path, html: { class: "new_post", id: "new_post" } do |f| %>
|
277
|
+
# ...
|
278
|
+
# <% end %>
|
279
|
+
#
|
280
|
+
# However you can still overwrite individual conventions, such as:
|
281
|
+
#
|
282
|
+
# <%= form_for(@post, url: super_posts_path) do |f| %>
|
283
|
+
# ...
|
284
|
+
# <% end %>
|
285
|
+
#
|
286
|
+
# You can also set the answer format, like this:
|
287
|
+
#
|
288
|
+
# <%= form_for(@post, format: :json) do |f| %>
|
289
|
+
# ...
|
290
|
+
# <% end %>
|
291
|
+
#
|
292
|
+
# For namespaced routes, like +admin_post_url+:
|
293
|
+
#
|
294
|
+
# <%= form_for([:admin, @post]) do |f| %>
|
295
|
+
# ...
|
296
|
+
# <% end %>
|
297
|
+
#
|
298
|
+
# If your resource has associations defined, for example, you want to add comments
|
299
|
+
# to the document given that the routes are set correctly:
|
300
|
+
#
|
301
|
+
# <%= form_for([@document, @comment]) do |f| %>
|
302
|
+
# ...
|
303
|
+
# <% end %>
|
304
|
+
#
|
305
|
+
# Where <tt>@document = Document.find(params[:id])</tt> and
|
306
|
+
# <tt>@comment = Comment.new</tt>.
|
307
|
+
#
|
308
|
+
# === Setting the method
|
309
|
+
#
|
310
|
+
# You can force the form to use the full array of HTTP verbs by setting
|
311
|
+
#
|
312
|
+
# method: (:get|:post|:patch|:put|:delete)
|
313
|
+
#
|
314
|
+
# in the options hash. If the verb is not GET or POST, which are natively
|
315
|
+
# supported by HTML forms, the form will be set to POST and a hidden input
|
316
|
+
# called _method will carry the intended verb for the server to interpret.
|
317
|
+
#
|
318
|
+
# === Unobtrusive JavaScript
|
319
|
+
#
|
320
|
+
# Specifying:
|
321
|
+
#
|
322
|
+
# remote: true
|
323
|
+
#
|
324
|
+
# in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its
|
325
|
+
# behavior. The expected default behavior is an XMLHttpRequest in the background instead of the regular
|
326
|
+
# POST arrangement, but ultimately the behavior is the choice of the JavaScript driver implementor.
|
327
|
+
# Even though it's using JavaScript to serialize the form elements, the form submission will work just like
|
328
|
+
# a regular submission as viewed by the receiving side (all elements available in <tt>params</tt>).
|
329
|
+
#
|
330
|
+
# Example:
|
331
|
+
#
|
332
|
+
# <%= form_for(@post, remote: true) do |f| %>
|
333
|
+
# ...
|
334
|
+
# <% end %>
|
335
|
+
#
|
336
|
+
# The HTML generated for this would be:
|
337
|
+
#
|
338
|
+
# <form action='http://www.example.com' method='post' data-remote='true'>
|
339
|
+
# <input name='_method' type='hidden' value='patch' />
|
340
|
+
# ...
|
341
|
+
# </form>
|
342
|
+
#
|
343
|
+
# === Setting HTML options
|
344
|
+
#
|
345
|
+
# You can set data attributes directly by passing in a data hash, but all other HTML options must be wrapped in
|
346
|
+
# the HTML key. Example:
|
347
|
+
#
|
348
|
+
# <%= form_for(@post, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %>
|
349
|
+
# ...
|
350
|
+
# <% end %>
|
351
|
+
#
|
352
|
+
# The HTML generated for this would be:
|
353
|
+
#
|
354
|
+
# <form action='http://www.example.com' method='post' data-behavior='autosave' name='go'>
|
355
|
+
# <input name='_method' type='hidden' value='patch' />
|
356
|
+
# ...
|
357
|
+
# </form>
|
358
|
+
#
|
359
|
+
# === Removing hidden model id's
|
360
|
+
#
|
361
|
+
# The form_for method automatically includes the model id as a hidden field in the form.
|
362
|
+
# This is used to maintain the correlation between the form data and its associated model.
|
363
|
+
# Some ORM systems do not use IDs on nested models so in this case you want to be able
|
364
|
+
# to disable the hidden id.
|
365
|
+
#
|
366
|
+
# In the following example the Post model has many Comments stored within it in a NoSQL database,
|
367
|
+
# thus there is no primary key for comments.
|
368
|
+
#
|
369
|
+
# Example:
|
370
|
+
#
|
371
|
+
# <%= form_for(@post) do |f| %>
|
372
|
+
# <%= f.fields_for(:comments, include_id: false) do |cf| %>
|
373
|
+
# ...
|
374
|
+
# <% end %>
|
375
|
+
# <% end %>
|
376
|
+
#
|
377
|
+
# === Customized form builders
|
378
|
+
#
|
379
|
+
# You can also build forms using a customized FormBuilder class. Subclass
|
380
|
+
# FormBuilder and override or define some more helpers, then use your
|
381
|
+
# custom builder. For example, let's say you made a helper to
|
382
|
+
# automatically add labels to form inputs.
|
383
|
+
#
|
384
|
+
# <%= form_for @person, url: { action: "create" }, builder: LabellingFormBuilder do |f| %>
|
385
|
+
# <%= f.text_field :first_name %>
|
386
|
+
# <%= f.text_field :last_name %>
|
387
|
+
# <%= f.text_area :biography %>
|
388
|
+
# <%= f.check_box :admin %>
|
389
|
+
# <%= f.submit %>
|
390
|
+
# <% end %>
|
391
|
+
#
|
392
|
+
# In this case, if you use this:
|
393
|
+
#
|
394
|
+
# <%= render f %>
|
395
|
+
#
|
396
|
+
# The rendered template is <tt>people/_labelling_form</tt> and the local
|
397
|
+
# variable referencing the form builder is called
|
398
|
+
# <tt>labelling_form</tt>.
|
399
|
+
#
|
400
|
+
# The custom FormBuilder class is automatically merged with the options
|
401
|
+
# of a nested fields_for call, unless it's explicitly set.
|
402
|
+
#
|
403
|
+
# In many cases you will want to wrap the above in another helper, so you
|
404
|
+
# could do something like the following:
|
405
|
+
#
|
406
|
+
# def labelled_form_for(record_or_name_or_array, *args, &block)
|
407
|
+
# options = args.extract_options!
|
408
|
+
# form_for(record_or_name_or_array, *(args << options.merge(builder: LabellingFormBuilder)), &block)
|
409
|
+
# end
|
410
|
+
#
|
411
|
+
# If you don't need to attach a form to a model instance, then check out
|
412
|
+
# FormTagHelper#form_tag.
|
413
|
+
#
|
414
|
+
# === Form to external resources
|
415
|
+
#
|
416
|
+
# When you build forms to external resources sometimes you need to set an authenticity token or just render a form
|
417
|
+
# without it, for example when you submit data to a payment gateway number and types of fields could be limited.
|
418
|
+
#
|
419
|
+
# To set an authenticity token you need to pass an <tt>:authenticity_token</tt> parameter
|
420
|
+
#
|
421
|
+
# <%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f| %>
|
422
|
+
# ...
|
423
|
+
# <% end %>
|
424
|
+
#
|
425
|
+
# If you don't want to an authenticity token field be rendered at all just pass <tt>false</tt>:
|
426
|
+
#
|
427
|
+
# <%= form_for @invoice, url: external_url, authenticity_token: false do |f| %>
|
428
|
+
# ...
|
429
|
+
# <% end %>
|
430
|
+
def form_for(record, options = {}, &block)
|
431
|
+
raise ArgumentError, "Missing block" unless block_given?
|
432
|
+
html_options = options[:html] ||= {}
|
433
|
+
|
434
|
+
case record
|
435
|
+
when String, Symbol
|
436
|
+
object_name = record
|
437
|
+
object = nil
|
438
|
+
else
|
439
|
+
object = record.is_a?(Array) ? record.last : record
|
440
|
+
raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
|
441
|
+
object_name = options[:as] || model_name_from_record_or_class(object).param_key
|
442
|
+
apply_form_for_options!(record, object, options)
|
443
|
+
end
|
444
|
+
|
445
|
+
html_options[:data] = options.delete(:data) if options.has_key?(:data)
|
446
|
+
html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
|
447
|
+
html_options[:method] = options.delete(:method) if options.has_key?(:method)
|
448
|
+
html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
|
449
|
+
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
450
|
+
|
451
|
+
builder = instantiate_builder(object_name, object, options)
|
452
|
+
output = capture(builder, &block)
|
453
|
+
html_options[:multipart] ||= builder.multipart?
|
454
|
+
|
455
|
+
html_options = html_options_for_form(options[:url] || {}, html_options)
|
456
|
+
form_tag_with_body(html_options, output)
|
457
|
+
end
|
458
|
+
|
459
|
+
def apply_form_for_options!(record, object, options) #:nodoc:
|
460
|
+
object = convert_to_model(object)
|
461
|
+
|
462
|
+
as = options[:as]
|
463
|
+
namespace = options[:namespace]
|
464
|
+
action, method = object.respond_to?(:persisted?) && object.persisted? ? [:edit, :patch] : [:new, :post]
|
465
|
+
options[:html].reverse_merge!(
|
466
|
+
class: as ? "#{action}_#{as}" : dom_class(object, action),
|
467
|
+
id: (as ? [namespace, action, as] : [namespace, dom_id(object, action)]).compact.join("_").presence,
|
468
|
+
method: method
|
469
|
+
)
|
470
|
+
|
471
|
+
options[:url] ||= if options.key?(:format)
|
472
|
+
polymorphic_path(record, format: options.delete(:format))
|
473
|
+
else
|
474
|
+
polymorphic_path(record, {})
|
475
|
+
end
|
476
|
+
end
|
477
|
+
private :apply_form_for_options!
|
478
|
+
|
479
|
+
mattr_accessor :form_with_generates_remote_forms, default: true
|
480
|
+
|
481
|
+
mattr_accessor :form_with_generates_ids, default: false
|
482
|
+
|
483
|
+
# Creates a form tag based on mixing URLs, scopes, or models.
|
484
|
+
#
|
485
|
+
# # Using just a URL:
|
486
|
+
# <%= form_with url: posts_path do |form| %>
|
487
|
+
# <%= form.text_field :title %>
|
488
|
+
# <% end %>
|
489
|
+
# # =>
|
490
|
+
# <form action="/posts" method="post" data-remote="true">
|
491
|
+
# <input type="text" name="title">
|
492
|
+
# </form>
|
493
|
+
#
|
494
|
+
# # Adding a scope prefixes the input field names:
|
495
|
+
# <%= form_with scope: :post, url: posts_path do |form| %>
|
496
|
+
# <%= form.text_field :title %>
|
497
|
+
# <% end %>
|
498
|
+
# # =>
|
499
|
+
# <form action="/posts" method="post" data-remote="true">
|
500
|
+
# <input type="text" name="post[title]">
|
501
|
+
# </form>
|
502
|
+
#
|
503
|
+
# # Using a model infers both the URL and scope:
|
504
|
+
# <%= form_with model: Post.new do |form| %>
|
505
|
+
# <%= form.text_field :title %>
|
506
|
+
# <% end %>
|
507
|
+
# # =>
|
508
|
+
# <form action="/posts" method="post" data-remote="true">
|
509
|
+
# <input type="text" name="post[title]">
|
510
|
+
# </form>
|
511
|
+
#
|
512
|
+
# # An existing model makes an update form and fills out field values:
|
513
|
+
# <%= form_with model: Post.first do |form| %>
|
514
|
+
# <%= form.text_field :title %>
|
515
|
+
# <% end %>
|
516
|
+
# # =>
|
517
|
+
# <form action="/posts/1" method="post" data-remote="true">
|
518
|
+
# <input type="hidden" name="_method" value="patch">
|
519
|
+
# <input type="text" name="post[title]" value="<the title of the post>">
|
520
|
+
# </form>
|
521
|
+
#
|
522
|
+
# # Though the fields don't have to correspond to model attributes:
|
523
|
+
# <%= form_with model: Cat.new do |form| %>
|
524
|
+
# <%= form.text_field :cats_dont_have_gills %>
|
525
|
+
# <%= form.text_field :but_in_forms_they_can %>
|
526
|
+
# <% end %>
|
527
|
+
# # =>
|
528
|
+
# <form action="/cats" method="post" data-remote="true">
|
529
|
+
# <input type="text" name="cat[cats_dont_have_gills]">
|
530
|
+
# <input type="text" name="cat[but_in_forms_they_can]">
|
531
|
+
# </form>
|
532
|
+
#
|
533
|
+
# The parameters in the forms are accessible in controllers according to
|
534
|
+
# their name nesting. So inputs named +title+ and <tt>post[title]</tt> are
|
535
|
+
# accessible as <tt>params[:title]</tt> and <tt>params[:post][:title]</tt>
|
536
|
+
# respectively.
|
537
|
+
#
|
538
|
+
# By default +form_with+ attaches the <tt>data-remote</tt> attribute
|
539
|
+
# submitting the form via an XMLHTTPRequest in the background if an
|
540
|
+
# Unobtrusive JavaScript driver, like rails-ujs, is used. See the
|
541
|
+
# <tt>:local</tt> option for more.
|
542
|
+
#
|
543
|
+
# For ease of comparison the examples above left out the submit button,
|
544
|
+
# as well as the auto generated hidden fields that enable UTF-8 support
|
545
|
+
# and adds an authenticity token needed for cross site request forgery
|
546
|
+
# protection.
|
547
|
+
#
|
548
|
+
# === Resource-oriented style
|
549
|
+
#
|
550
|
+
# In many of the examples just shown, the +:model+ passed to +form_with+
|
551
|
+
# is a _resource_. It corresponds to a set of RESTful routes, most likely
|
552
|
+
# defined via +resources+ in <tt>config/routes.rb</tt>.
|
553
|
+
#
|
554
|
+
# So when passing such a model record, Rails infers the URL and method.
|
555
|
+
#
|
556
|
+
# <%= form_with model: @post do |form| %>
|
557
|
+
# ...
|
558
|
+
# <% end %>
|
559
|
+
#
|
560
|
+
# is then equivalent to something like:
|
561
|
+
#
|
562
|
+
# <%= form_with scope: :post, url: post_path(@post), method: :patch do |form| %>
|
563
|
+
# ...
|
564
|
+
# <% end %>
|
565
|
+
#
|
566
|
+
# And for a new record
|
567
|
+
#
|
568
|
+
# <%= form_with model: Post.new do |form| %>
|
569
|
+
# ...
|
570
|
+
# <% end %>
|
571
|
+
#
|
572
|
+
# is equivalent to something like:
|
573
|
+
#
|
574
|
+
# <%= form_with scope: :post, url: posts_path do |form| %>
|
575
|
+
# ...
|
576
|
+
# <% end %>
|
577
|
+
#
|
578
|
+
# ==== +form_with+ options
|
579
|
+
#
|
580
|
+
# * <tt>:url</tt> - The URL the form submits to. Akin to values passed to
|
581
|
+
# +url_for+ or +link_to+. For example, you may use a named route
|
582
|
+
# directly. When a <tt>:scope</tt> is passed without a <tt>:url</tt> the
|
583
|
+
# form just submits to the current URL.
|
584
|
+
# * <tt>:method</tt> - The method to use when submitting the form, usually
|
585
|
+
# either "get" or "post". If "patch", "put", "delete", or another verb
|
586
|
+
# is used, a hidden input named <tt>_method</tt> is added to
|
587
|
+
# simulate the verb over post.
|
588
|
+
# * <tt>:format</tt> - The format of the route the form submits to.
|
589
|
+
# Useful when submitting to another resource type, like <tt>:json</tt>.
|
590
|
+
# Skipped if a <tt>:url</tt> is passed.
|
591
|
+
# * <tt>:scope</tt> - The scope to prefix input field names with and
|
592
|
+
# thereby how the submitted parameters are grouped in controllers.
|
593
|
+
# * <tt>:model</tt> - A model object to infer the <tt>:url</tt> and
|
594
|
+
# <tt>:scope</tt> by, plus fill out input field values.
|
595
|
+
# So if a +title+ attribute is set to "Ahoy!" then a +title+ input
|
596
|
+
# field's value would be "Ahoy!".
|
597
|
+
# If the model is a new record a create form is generated, if an
|
598
|
+
# existing record, however, an update form is generated.
|
599
|
+
# Pass <tt>:scope</tt> or <tt>:url</tt> to override the defaults.
|
600
|
+
# E.g. turn <tt>params[:post]</tt> into <tt>params[:article]</tt>.
|
601
|
+
# * <tt>:authenticity_token</tt> - Authenticity token to use in the form.
|
602
|
+
# Override with a custom authenticity token or pass <tt>false</tt> to
|
603
|
+
# skip the authenticity token field altogether.
|
604
|
+
# Useful when submitting to an external resource like a payment gateway
|
605
|
+
# that might limit the valid fields.
|
606
|
+
# Remote forms may omit the embedded authenticity token by setting
|
607
|
+
# <tt>config.action_view.embed_authenticity_token_in_remote_forms = false</tt>.
|
608
|
+
# This is helpful when fragment-caching the form. Remote forms
|
609
|
+
# get the authenticity token from the <tt>meta</tt> tag, so embedding is
|
610
|
+
# unnecessary unless you support browsers without JavaScript.
|
611
|
+
# * <tt>:local</tt> - By default form submits are remote and unobtrusive XHRs.
|
612
|
+
# Disable remote submits with <tt>local: true</tt>.
|
613
|
+
# * <tt>:skip_enforcing_utf8</tt> - By default a hidden field named +utf8+
|
614
|
+
# is output to enforce UTF-8 submits. Set to true to skip the field.
|
615
|
+
# * <tt>:builder</tt> - Override the object used to build the form.
|
616
|
+
# * <tt>:id</tt> - Optional HTML id attribute.
|
617
|
+
# * <tt>:class</tt> - Optional HTML class attribute.
|
618
|
+
# * <tt>:data</tt> - Optional HTML data attributes.
|
619
|
+
# * <tt>:html</tt> - Other optional HTML attributes for the form tag.
|
620
|
+
#
|
621
|
+
# === Examples
|
622
|
+
#
|
623
|
+
# When not passing a block, +form_with+ just generates an opening form tag.
|
624
|
+
#
|
625
|
+
# <%= form_with(model: @post, url: super_posts_path) %>
|
626
|
+
# <%= form_with(model: @post, scope: :article) %>
|
627
|
+
# <%= form_with(model: @post, format: :json) %>
|
628
|
+
# <%= form_with(model: @post, authenticity_token: false) %> # Disables the token.
|
629
|
+
#
|
630
|
+
# For namespaced routes, like +admin_post_url+:
|
631
|
+
#
|
632
|
+
# <%= form_with(model: [ :admin, @post ]) do |form| %>
|
633
|
+
# ...
|
634
|
+
# <% end %>
|
635
|
+
#
|
636
|
+
# If your resource has associations defined, for example, you want to add comments
|
637
|
+
# to the document given that the routes are set correctly:
|
638
|
+
#
|
639
|
+
# <%= form_with(model: [ @document, Comment.new ]) do |form| %>
|
640
|
+
# ...
|
641
|
+
# <% end %>
|
642
|
+
#
|
643
|
+
# Where <tt>@document = Document.find(params[:id])</tt>.
|
644
|
+
#
|
645
|
+
# === Mixing with other form helpers
|
646
|
+
#
|
647
|
+
# While +form_with+ uses a FormBuilder object it's possible to mix and
|
648
|
+
# match the stand-alone FormHelper methods and methods
|
649
|
+
# from FormTagHelper:
|
650
|
+
#
|
651
|
+
# <%= form_with scope: :person do |form| %>
|
652
|
+
# <%= form.text_field :first_name %>
|
653
|
+
# <%= form.text_field :last_name %>
|
654
|
+
#
|
655
|
+
# <%= text_area :person, :biography %>
|
656
|
+
# <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
|
657
|
+
#
|
658
|
+
# <%= form.submit %>
|
659
|
+
# <% end %>
|
660
|
+
#
|
661
|
+
# Same goes for the methods in FormOptionsHelper and DateHelper designed
|
662
|
+
# to work with an object as a base, like
|
663
|
+
# FormOptionsHelper#collection_select and DateHelper#datetime_select.
|
664
|
+
#
|
665
|
+
# === Setting the method
|
666
|
+
#
|
667
|
+
# You can force the form to use the full array of HTTP verbs by setting
|
668
|
+
#
|
669
|
+
# method: (:get|:post|:patch|:put|:delete)
|
670
|
+
#
|
671
|
+
# in the options hash. If the verb is not GET or POST, which are natively
|
672
|
+
# supported by HTML forms, the form will be set to POST and a hidden input
|
673
|
+
# called _method will carry the intended verb for the server to interpret.
|
674
|
+
#
|
675
|
+
# === Setting HTML options
|
676
|
+
#
|
677
|
+
# You can set data attributes directly in a data hash, but HTML options
|
678
|
+
# besides id and class must be wrapped in an HTML key:
|
679
|
+
#
|
680
|
+
# <%= form_with(model: @post, data: { behavior: "autosave" }, html: { name: "go" }) do |form| %>
|
681
|
+
# ...
|
682
|
+
# <% end %>
|
683
|
+
#
|
684
|
+
# generates
|
685
|
+
#
|
686
|
+
# <form action="/posts/123" method="post" data-behavior="autosave" name="go">
|
687
|
+
# <input name="_method" type="hidden" value="patch" />
|
688
|
+
# ...
|
689
|
+
# </form>
|
690
|
+
#
|
691
|
+
# === Removing hidden model id's
|
692
|
+
#
|
693
|
+
# The +form_with+ method automatically includes the model id as a hidden field in the form.
|
694
|
+
# This is used to maintain the correlation between the form data and its associated model.
|
695
|
+
# Some ORM systems do not use IDs on nested models so in this case you want to be able
|
696
|
+
# to disable the hidden id.
|
697
|
+
#
|
698
|
+
# In the following example the Post model has many Comments stored within it in a NoSQL database,
|
699
|
+
# thus there is no primary key for comments.
|
700
|
+
#
|
701
|
+
# <%= form_with(model: @post) do |form| %>
|
702
|
+
# <%= form.fields(:comments, skip_id: true) do |fields| %>
|
703
|
+
# ...
|
704
|
+
# <% end %>
|
705
|
+
# <% end %>
|
706
|
+
#
|
707
|
+
# === Customized form builders
|
708
|
+
#
|
709
|
+
# You can also build forms using a customized FormBuilder class. Subclass
|
710
|
+
# FormBuilder and override or define some more helpers, then use your
|
711
|
+
# custom builder. For example, let's say you made a helper to
|
712
|
+
# automatically add labels to form inputs.
|
713
|
+
#
|
714
|
+
# <%= form_with model: @person, url: { action: "create" }, builder: LabellingFormBuilder do |form| %>
|
715
|
+
# <%= form.text_field :first_name %>
|
716
|
+
# <%= form.text_field :last_name %>
|
717
|
+
# <%= form.text_area :biography %>
|
718
|
+
# <%= form.check_box :admin %>
|
719
|
+
# <%= form.submit %>
|
720
|
+
# <% end %>
|
721
|
+
#
|
722
|
+
# In this case, if you use:
|
723
|
+
#
|
724
|
+
# <%= render form %>
|
725
|
+
#
|
726
|
+
# The rendered template is <tt>people/_labelling_form</tt> and the local
|
727
|
+
# variable referencing the form builder is called
|
728
|
+
# <tt>labelling_form</tt>.
|
729
|
+
#
|
730
|
+
# The custom FormBuilder class is automatically merged with the options
|
731
|
+
# of a nested +fields+ call, unless it's explicitly set.
|
732
|
+
#
|
733
|
+
# In many cases you will want to wrap the above in another helper, so you
|
734
|
+
# could do something like the following:
|
735
|
+
#
|
736
|
+
# def labelled_form_with(**options, &block)
|
737
|
+
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
|
738
|
+
# end
|
739
|
+
def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
|
740
|
+
options[:allow_method_names_outside_object] = true
|
741
|
+
options[:skip_default_ids] = !form_with_generates_ids
|
742
|
+
|
743
|
+
if model
|
744
|
+
url ||= polymorphic_path(model, format: format)
|
745
|
+
|
746
|
+
model = model.last if model.is_a?(Array)
|
747
|
+
scope ||= model_name_from_record_or_class(model).param_key
|
748
|
+
end
|
749
|
+
|
750
|
+
if block_given?
|
751
|
+
builder = instantiate_builder(scope, model, options)
|
752
|
+
output = capture(builder, &Proc.new)
|
753
|
+
options[:multipart] ||= builder.multipart?
|
754
|
+
|
755
|
+
html_options = html_options_for_form_with(url, model, options)
|
756
|
+
form_tag_with_body(html_options, output)
|
757
|
+
else
|
758
|
+
html_options = html_options_for_form_with(url, model, options)
|
759
|
+
form_tag_html(html_options)
|
760
|
+
end
|
761
|
+
end
|
762
|
+
|
763
|
+
# Creates a scope around a specific model object like form_for, but
|
764
|
+
# doesn't create the form tags themselves. This makes fields_for suitable
|
765
|
+
# for specifying additional model objects in the same form.
|
766
|
+
#
|
767
|
+
# Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
|
768
|
+
# its method signature is slightly different. Like +form_for+, it yields
|
769
|
+
# a FormBuilder object associated with a particular model object to a block,
|
770
|
+
# and within the block allows methods to be called on the builder to
|
771
|
+
# generate fields associated with the model object. Fields may reflect
|
772
|
+
# a model object in two ways - how they are named (hence how submitted
|
773
|
+
# values appear within the +params+ hash in the controller) and what
|
774
|
+
# default values are shown when the form the fields appear in is first
|
775
|
+
# displayed. In order for both of these features to be specified independently,
|
776
|
+
# both an object name (represented by either a symbol or string) and the
|
777
|
+
# object itself can be passed to the method separately -
|
778
|
+
#
|
779
|
+
# <%= form_for @person do |person_form| %>
|
780
|
+
# First name: <%= person_form.text_field :first_name %>
|
781
|
+
# Last name : <%= person_form.text_field :last_name %>
|
782
|
+
#
|
783
|
+
# <%= fields_for :permission, @person.permission do |permission_fields| %>
|
784
|
+
# Admin? : <%= permission_fields.check_box :admin %>
|
785
|
+
# <% end %>
|
786
|
+
#
|
787
|
+
# <%= person_form.submit %>
|
788
|
+
# <% end %>
|
789
|
+
#
|
790
|
+
# In this case, the checkbox field will be represented by an HTML +input+
|
791
|
+
# tag with the +name+ attribute <tt>permission[admin]</tt>, and the submitted
|
792
|
+
# value will appear in the controller as <tt>params[:permission][:admin]</tt>.
|
793
|
+
# If <tt>@person.permission</tt> is an existing record with an attribute
|
794
|
+
# +admin+, the initial state of the checkbox when first displayed will
|
795
|
+
# reflect the value of <tt>@person.permission.admin</tt>.
|
796
|
+
#
|
797
|
+
# Often this can be simplified by passing just the name of the model
|
798
|
+
# object to +fields_for+ -
|
799
|
+
#
|
800
|
+
# <%= fields_for :permission do |permission_fields| %>
|
801
|
+
# Admin?: <%= permission_fields.check_box :admin %>
|
802
|
+
# <% end %>
|
803
|
+
#
|
804
|
+
# ...in which case, if <tt>:permission</tt> also happens to be the name of an
|
805
|
+
# instance variable <tt>@permission</tt>, the initial state of the input
|
806
|
+
# field will reflect the value of that variable's attribute <tt>@permission.admin</tt>.
|
807
|
+
#
|
808
|
+
# Alternatively, you can pass just the model object itself (if the first
|
809
|
+
# argument isn't a string or symbol +fields_for+ will realize that the
|
810
|
+
# name has been omitted) -
|
811
|
+
#
|
812
|
+
# <%= fields_for @person.permission do |permission_fields| %>
|
813
|
+
# Admin?: <%= permission_fields.check_box :admin %>
|
814
|
+
# <% end %>
|
815
|
+
#
|
816
|
+
# and +fields_for+ will derive the required name of the field from the
|
817
|
+
# _class_ of the model object, e.g. if <tt>@person.permission</tt>, is
|
818
|
+
# of class +Permission+, the field will still be named <tt>permission[admin]</tt>.
|
819
|
+
#
|
820
|
+
# Note: This also works for the methods in FormOptionsHelper and
|
821
|
+
# DateHelper that are designed to work with an object as base, like
|
822
|
+
# FormOptionsHelper#collection_select and DateHelper#datetime_select.
|
823
|
+
#
|
824
|
+
# === Nested Attributes Examples
|
825
|
+
#
|
826
|
+
# When the object belonging to the current scope has a nested attribute
|
827
|
+
# writer for a certain attribute, fields_for will yield a new scope
|
828
|
+
# for that attribute. This allows you to create forms that set or change
|
829
|
+
# the attributes of a parent object and its associations in one go.
|
830
|
+
#
|
831
|
+
# Nested attribute writers are normal setter methods named after an
|
832
|
+
# association. The most common way of defining these writers is either
|
833
|
+
# with +accepts_nested_attributes_for+ in a model definition or by
|
834
|
+
# defining a method with the proper name. For example: the attribute
|
835
|
+
# writer for the association <tt>:address</tt> is called
|
836
|
+
# <tt>address_attributes=</tt>.
|
837
|
+
#
|
838
|
+
# Whether a one-to-one or one-to-many style form builder will be yielded
|
839
|
+
# depends on whether the normal reader method returns a _single_ object
|
840
|
+
# or an _array_ of objects.
|
841
|
+
#
|
842
|
+
# ==== One-to-one
|
843
|
+
#
|
844
|
+
# Consider a Person class which returns a _single_ Address from the
|
845
|
+
# <tt>address</tt> reader method and responds to the
|
846
|
+
# <tt>address_attributes=</tt> writer method:
|
847
|
+
#
|
848
|
+
# class Person
|
849
|
+
# def address
|
850
|
+
# @address
|
851
|
+
# end
|
852
|
+
#
|
853
|
+
# def address_attributes=(attributes)
|
854
|
+
# # Process the attributes hash
|
855
|
+
# end
|
856
|
+
# end
|
857
|
+
#
|
858
|
+
# This model can now be used with a nested fields_for, like so:
|
859
|
+
#
|
860
|
+
# <%= form_for @person do |person_form| %>
|
861
|
+
# ...
|
862
|
+
# <%= person_form.fields_for :address do |address_fields| %>
|
863
|
+
# Street : <%= address_fields.text_field :street %>
|
864
|
+
# Zip code: <%= address_fields.text_field :zip_code %>
|
865
|
+
# <% end %>
|
866
|
+
# ...
|
867
|
+
# <% end %>
|
868
|
+
#
|
869
|
+
# When address is already an association on a Person you can use
|
870
|
+
# +accepts_nested_attributes_for+ to define the writer method for you:
|
871
|
+
#
|
872
|
+
# class Person < ActiveRecord::Base
|
873
|
+
# has_one :address
|
874
|
+
# accepts_nested_attributes_for :address
|
875
|
+
# end
|
876
|
+
#
|
877
|
+
# If you want to destroy the associated model through the form, you have
|
878
|
+
# to enable it first using the <tt>:allow_destroy</tt> option for
|
879
|
+
# +accepts_nested_attributes_for+:
|
880
|
+
#
|
881
|
+
# class Person < ActiveRecord::Base
|
882
|
+
# has_one :address
|
883
|
+
# accepts_nested_attributes_for :address, allow_destroy: true
|
884
|
+
# end
|
885
|
+
#
|
886
|
+
# Now, when you use a form element with the <tt>_destroy</tt> parameter,
|
887
|
+
# with a value that evaluates to +true+, you will destroy the associated
|
888
|
+
# model (eg. 1, '1', true, or 'true'):
|
889
|
+
#
|
890
|
+
# <%= form_for @person do |person_form| %>
|
891
|
+
# ...
|
892
|
+
# <%= person_form.fields_for :address do |address_fields| %>
|
893
|
+
# ...
|
894
|
+
# Delete: <%= address_fields.check_box :_destroy %>
|
895
|
+
# <% end %>
|
896
|
+
# ...
|
897
|
+
# <% end %>
|
898
|
+
#
|
899
|
+
# ==== One-to-many
|
900
|
+
#
|
901
|
+
# Consider a Person class which returns an _array_ of Project instances
|
902
|
+
# from the <tt>projects</tt> reader method and responds to the
|
903
|
+
# <tt>projects_attributes=</tt> writer method:
|
904
|
+
#
|
905
|
+
# class Person
|
906
|
+
# def projects
|
907
|
+
# [@project1, @project2]
|
908
|
+
# end
|
909
|
+
#
|
910
|
+
# def projects_attributes=(attributes)
|
911
|
+
# # Process the attributes hash
|
912
|
+
# end
|
913
|
+
# end
|
914
|
+
#
|
915
|
+
# Note that the <tt>projects_attributes=</tt> writer method is in fact
|
916
|
+
# required for fields_for to correctly identify <tt>:projects</tt> as a
|
917
|
+
# collection, and the correct indices to be set in the form markup.
|
918
|
+
#
|
919
|
+
# When projects is already an association on Person you can use
|
920
|
+
# +accepts_nested_attributes_for+ to define the writer method for you:
|
921
|
+
#
|
922
|
+
# class Person < ActiveRecord::Base
|
923
|
+
# has_many :projects
|
924
|
+
# accepts_nested_attributes_for :projects
|
925
|
+
# end
|
926
|
+
#
|
927
|
+
# This model can now be used with a nested fields_for. The block given to
|
928
|
+
# the nested fields_for call will be repeated for each instance in the
|
929
|
+
# collection:
|
930
|
+
#
|
931
|
+
# <%= form_for @person do |person_form| %>
|
932
|
+
# ...
|
933
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
934
|
+
# <% if project_fields.object.active? %>
|
935
|
+
# Name: <%= project_fields.text_field :name %>
|
936
|
+
# <% end %>
|
937
|
+
# <% end %>
|
938
|
+
# ...
|
939
|
+
# <% end %>
|
940
|
+
#
|
941
|
+
# It's also possible to specify the instance to be used:
|
942
|
+
#
|
943
|
+
# <%= form_for @person do |person_form| %>
|
944
|
+
# ...
|
945
|
+
# <% @person.projects.each do |project| %>
|
946
|
+
# <% if project.active? %>
|
947
|
+
# <%= person_form.fields_for :projects, project do |project_fields| %>
|
948
|
+
# Name: <%= project_fields.text_field :name %>
|
949
|
+
# <% end %>
|
950
|
+
# <% end %>
|
951
|
+
# <% end %>
|
952
|
+
# ...
|
953
|
+
# <% end %>
|
954
|
+
#
|
955
|
+
# Or a collection to be used:
|
956
|
+
#
|
957
|
+
# <%= form_for @person do |person_form| %>
|
958
|
+
# ...
|
959
|
+
# <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
|
960
|
+
# Name: <%= project_fields.text_field :name %>
|
961
|
+
# <% end %>
|
962
|
+
# ...
|
963
|
+
# <% end %>
|
964
|
+
#
|
965
|
+
# If you want to destroy any of the associated models through the
|
966
|
+
# form, you have to enable it first using the <tt>:allow_destroy</tt>
|
967
|
+
# option for +accepts_nested_attributes_for+:
|
968
|
+
#
|
969
|
+
# class Person < ActiveRecord::Base
|
970
|
+
# has_many :projects
|
971
|
+
# accepts_nested_attributes_for :projects, allow_destroy: true
|
972
|
+
# end
|
973
|
+
#
|
974
|
+
# This will allow you to specify which models to destroy in the
|
975
|
+
# attributes hash by adding a form element for the <tt>_destroy</tt>
|
976
|
+
# parameter with a value that evaluates to +true+
|
977
|
+
# (eg. 1, '1', true, or 'true'):
|
978
|
+
#
|
979
|
+
# <%= form_for @person do |person_form| %>
|
980
|
+
# ...
|
981
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
982
|
+
# Delete: <%= project_fields.check_box :_destroy %>
|
983
|
+
# <% end %>
|
984
|
+
# ...
|
985
|
+
# <% end %>
|
986
|
+
#
|
987
|
+
# When a collection is used you might want to know the index of each
|
988
|
+
# object into the array. For this purpose, the <tt>index</tt> method
|
989
|
+
# is available in the FormBuilder object.
|
990
|
+
#
|
991
|
+
# <%= form_for @person do |person_form| %>
|
992
|
+
# ...
|
993
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
994
|
+
# Project #<%= project_fields.index %>
|
995
|
+
# ...
|
996
|
+
# <% end %>
|
997
|
+
# ...
|
998
|
+
# <% end %>
|
999
|
+
#
|
1000
|
+
# Note that fields_for will automatically generate a hidden field
|
1001
|
+
# to store the ID of the record. There are circumstances where this
|
1002
|
+
# hidden field is not needed and you can pass <tt>include_id: false</tt>
|
1003
|
+
# to prevent fields_for from rendering it automatically.
|
1004
|
+
def fields_for(record_name, record_object = nil, options = {}, &block)
|
1005
|
+
builder = instantiate_builder(record_name, record_object, options)
|
1006
|
+
capture(builder, &block)
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
# Scopes input fields with either an explicit scope or model.
|
1010
|
+
# Like +form_with+ does with <tt>:scope</tt> or <tt>:model</tt>,
|
1011
|
+
# except it doesn't output the form tags.
|
1012
|
+
#
|
1013
|
+
# # Using a scope prefixes the input field names:
|
1014
|
+
# <%= fields :comment do |fields| %>
|
1015
|
+
# <%= fields.text_field :body %>
|
1016
|
+
# <% end %>
|
1017
|
+
# # => <input type="text" name="comment[body]">
|
1018
|
+
#
|
1019
|
+
# # Using a model infers the scope and assigns field values:
|
1020
|
+
# <%= fields model: Comment.new(body: "full bodied") do |fields| %>
|
1021
|
+
# <%= fields.text_field :body %>
|
1022
|
+
# <% end %>
|
1023
|
+
# # => <input type="text" name="comment[body]" value="full bodied">
|
1024
|
+
#
|
1025
|
+
# # Using +fields+ with +form_with+:
|
1026
|
+
# <%= form_with model: @post do |form| %>
|
1027
|
+
# <%= form.text_field :title %>
|
1028
|
+
#
|
1029
|
+
# <%= form.fields :comment do |fields| %>
|
1030
|
+
# <%= fields.text_field :body %>
|
1031
|
+
# <% end %>
|
1032
|
+
# <% end %>
|
1033
|
+
#
|
1034
|
+
# Much like +form_with+ a FormBuilder instance associated with the scope
|
1035
|
+
# or model is yielded, so any generated field names are prefixed with
|
1036
|
+
# either the passed scope or the scope inferred from the <tt>:model</tt>.
|
1037
|
+
#
|
1038
|
+
# === Mixing with other form helpers
|
1039
|
+
#
|
1040
|
+
# While +form_with+ uses a FormBuilder object it's possible to mix and
|
1041
|
+
# match the stand-alone FormHelper methods and methods
|
1042
|
+
# from FormTagHelper:
|
1043
|
+
#
|
1044
|
+
# <%= fields model: @comment do |fields| %>
|
1045
|
+
# <%= fields.text_field :body %>
|
1046
|
+
#
|
1047
|
+
# <%= text_area :commenter, :biography %>
|
1048
|
+
# <%= check_box_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
|
1049
|
+
# <% end %>
|
1050
|
+
#
|
1051
|
+
# Same goes for the methods in FormOptionsHelper and DateHelper designed
|
1052
|
+
# to work with an object as a base, like
|
1053
|
+
# FormOptionsHelper#collection_select and DateHelper#datetime_select.
|
1054
|
+
def fields(scope = nil, model: nil, **options, &block)
|
1055
|
+
options[:allow_method_names_outside_object] = true
|
1056
|
+
options[:skip_default_ids] = !form_with_generates_ids
|
1057
|
+
|
1058
|
+
if model
|
1059
|
+
scope ||= model_name_from_record_or_class(model).param_key
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
builder = instantiate_builder(scope, model, options)
|
1063
|
+
capture(builder, &block)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object
|
1067
|
+
# assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation
|
1068
|
+
# is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly.
|
1069
|
+
# Additional options on the label tag can be passed as a hash with +options+. These options will be tagged
|
1070
|
+
# onto the HTML as an HTML element attribute as in the example shown, except for the <tt>:value</tt> option, which is designed to
|
1071
|
+
# target labels for radio_button tags (where the value is used in the ID of the input tag).
|
1072
|
+
#
|
1073
|
+
# ==== Examples
|
1074
|
+
# label(:post, :title)
|
1075
|
+
# # => <label for="post_title">Title</label>
|
1076
|
+
#
|
1077
|
+
# You can localize your labels based on model and attribute names.
|
1078
|
+
# For example you can define the following in your locale (e.g. en.yml)
|
1079
|
+
#
|
1080
|
+
# helpers:
|
1081
|
+
# label:
|
1082
|
+
# post:
|
1083
|
+
# body: "Write your entire text here"
|
1084
|
+
#
|
1085
|
+
# Which then will result in
|
1086
|
+
#
|
1087
|
+
# label(:post, :body)
|
1088
|
+
# # => <label for="post_body">Write your entire text here</label>
|
1089
|
+
#
|
1090
|
+
# Localization can also be based purely on the translation of the attribute-name
|
1091
|
+
# (if you are using ActiveRecord):
|
1092
|
+
#
|
1093
|
+
# activerecord:
|
1094
|
+
# attributes:
|
1095
|
+
# post:
|
1096
|
+
# cost: "Total cost"
|
1097
|
+
#
|
1098
|
+
# label(:post, :cost)
|
1099
|
+
# # => <label for="post_cost">Total cost</label>
|
1100
|
+
#
|
1101
|
+
# label(:post, :title, "A short title")
|
1102
|
+
# # => <label for="post_title">A short title</label>
|
1103
|
+
#
|
1104
|
+
# label(:post, :title, "A short title", class: "title_label")
|
1105
|
+
# # => <label for="post_title" class="title_label">A short title</label>
|
1106
|
+
#
|
1107
|
+
# label(:post, :privacy, "Public Post", value: "public")
|
1108
|
+
# # => <label for="post_privacy_public">Public Post</label>
|
1109
|
+
#
|
1110
|
+
# label(:post, :terms) do
|
1111
|
+
# raw('Accept <a href="/terms">Terms</a>.')
|
1112
|
+
# end
|
1113
|
+
# # => <label for="post_terms">Accept <a href="/terms">Terms</a>.</label>
|
1114
|
+
def label(object_name, method, content_or_options = nil, options = nil, &block)
|
1115
|
+
Tags::Label.new(object_name, method, self, content_or_options, options).render(&block)
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
# Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) on an object
|
1119
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
1120
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
1121
|
+
# shown.
|
1122
|
+
#
|
1123
|
+
# ==== Examples
|
1124
|
+
# text_field(:post, :title, size: 20)
|
1125
|
+
# # => <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />
|
1126
|
+
#
|
1127
|
+
# text_field(:post, :title, class: "create_input")
|
1128
|
+
# # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" class="create_input" />
|
1129
|
+
#
|
1130
|
+
# text_field(:session, :user, onchange: "if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }")
|
1131
|
+
# # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange="if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }"/>
|
1132
|
+
#
|
1133
|
+
# text_field(:snippet, :code, size: 20, class: 'code_input')
|
1134
|
+
# # => <input type="text" id="snippet_code" name="snippet[code]" size="20" value="#{@snippet.code}" class="code_input" />
|
1135
|
+
def text_field(object_name, method, options = {})
|
1136
|
+
Tags::TextField.new(object_name, method, self, options).render
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
# Returns an input tag of the "password" type tailored for accessing a specified attribute (identified by +method+) on an object
|
1140
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
1141
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
1142
|
+
# shown. For security reasons this field is blank by default; pass in a value via +options+ if this is not desired.
|
1143
|
+
#
|
1144
|
+
# ==== Examples
|
1145
|
+
# password_field(:login, :pass, size: 20)
|
1146
|
+
# # => <input type="password" id="login_pass" name="login[pass]" size="20" />
|
1147
|
+
#
|
1148
|
+
# password_field(:account, :secret, class: "form_input", value: @account.secret)
|
1149
|
+
# # => <input type="password" id="account_secret" name="account[secret]" value="#{@account.secret}" class="form_input" />
|
1150
|
+
#
|
1151
|
+
# password_field(:user, :password, onchange: "if ($('#user_password').val().length > 30) { alert('Your password needs to be shorter!'); }")
|
1152
|
+
# # => <input type="password" id="user_password" name="user[password]" onchange="if ($('#user_password').val().length > 30) { alert('Your password needs to be shorter!'); }"/>
|
1153
|
+
#
|
1154
|
+
# password_field(:account, :pin, size: 20, class: 'form_input')
|
1155
|
+
# # => <input type="password" id="account_pin" name="account[pin]" size="20" class="form_input" />
|
1156
|
+
def password_field(object_name, method, options = {})
|
1157
|
+
Tags::PasswordField.new(object_name, method, self, options).render
|
1158
|
+
end
|
1159
|
+
|
1160
|
+
# Returns a hidden input tag tailored for accessing a specified attribute (identified by +method+) on an object
|
1161
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
1162
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
1163
|
+
# shown.
|
1164
|
+
#
|
1165
|
+
# ==== Examples
|
1166
|
+
# hidden_field(:signup, :pass_confirm)
|
1167
|
+
# # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="#{@signup.pass_confirm}" />
|
1168
|
+
#
|
1169
|
+
# hidden_field(:post, :tag_list)
|
1170
|
+
# # => <input type="hidden" id="post_tag_list" name="post[tag_list]" value="#{@post.tag_list}" />
|
1171
|
+
#
|
1172
|
+
# hidden_field(:user, :token)
|
1173
|
+
# # => <input type="hidden" id="user_token" name="user[token]" value="#{@user.token}" />
|
1174
|
+
def hidden_field(object_name, method, options = {})
|
1175
|
+
Tags::HiddenField.new(object_name, method, self, options).render
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
# Returns a file upload input tag tailored for accessing a specified attribute (identified by +method+) on an object
|
1179
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
1180
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
1181
|
+
# shown.
|
1182
|
+
#
|
1183
|
+
# Using this method inside a +form_for+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
|
1184
|
+
#
|
1185
|
+
# ==== Options
|
1186
|
+
# * Creates standard HTML attributes for the tag.
|
1187
|
+
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
|
1188
|
+
# * <tt>:multiple</tt> - If set to true, *in most updated browsers* the user will be allowed to select multiple files.
|
1189
|
+
# * <tt>:accept</tt> - If set to one or multiple mime-types, the user will be suggested a filter when choosing a file. You still need to set up model validations.
|
1190
|
+
#
|
1191
|
+
# ==== Examples
|
1192
|
+
# file_field(:user, :avatar)
|
1193
|
+
# # => <input type="file" id="user_avatar" name="user[avatar]" />
|
1194
|
+
#
|
1195
|
+
# file_field(:post, :image, multiple: true)
|
1196
|
+
# # => <input type="file" id="post_image" name="post[image][]" multiple="multiple" />
|
1197
|
+
#
|
1198
|
+
# file_field(:post, :attached, accept: 'text/html')
|
1199
|
+
# # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
|
1200
|
+
#
|
1201
|
+
# file_field(:post, :image, accept: 'image/png,image/gif,image/jpeg')
|
1202
|
+
# # => <input type="file" id="post_image" name="post[image]" accept="image/png,image/gif,image/jpeg" />
|
1203
|
+
#
|
1204
|
+
# file_field(:attachment, :file, class: 'file_input')
|
1205
|
+
# # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
|
1206
|
+
def file_field(object_name, method, options = {})
|
1207
|
+
Tags::FileField.new(object_name, method, self, convert_direct_upload_option_to_url(options.dup)).render
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
# Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
|
1211
|
+
# on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
1212
|
+
# hash with +options+.
|
1213
|
+
#
|
1214
|
+
# ==== Examples
|
1215
|
+
# text_area(:post, :body, cols: 20, rows: 40)
|
1216
|
+
# # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
|
1217
|
+
# # #{@post.body}
|
1218
|
+
# # </textarea>
|
1219
|
+
#
|
1220
|
+
# text_area(:comment, :text, size: "20x30")
|
1221
|
+
# # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
|
1222
|
+
# # #{@comment.text}
|
1223
|
+
# # </textarea>
|
1224
|
+
#
|
1225
|
+
# text_area(:application, :notes, cols: 40, rows: 15, class: 'app_input')
|
1226
|
+
# # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
|
1227
|
+
# # #{@application.notes}
|
1228
|
+
# # </textarea>
|
1229
|
+
#
|
1230
|
+
# text_area(:entry, :body, size: "20x20", disabled: 'disabled')
|
1231
|
+
# # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
|
1232
|
+
# # #{@entry.body}
|
1233
|
+
# # </textarea>
|
1234
|
+
def text_area(object_name, method, options = {})
|
1235
|
+
Tags::TextArea.new(object_name, method, self, options).render
|
1236
|
+
end
|
1237
|
+
|
1238
|
+
# Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object
|
1239
|
+
# assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object.
|
1240
|
+
# It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked.
|
1241
|
+
# Additional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1
|
1242
|
+
# while the default +unchecked_value+ is set to 0 which is convenient for boolean values.
|
1243
|
+
#
|
1244
|
+
# ==== Gotcha
|
1245
|
+
#
|
1246
|
+
# The HTML specification says unchecked check boxes are not successful, and
|
1247
|
+
# thus web browsers do not send them. Unfortunately this introduces a gotcha:
|
1248
|
+
# if an +Invoice+ model has a +paid+ flag, and in the form that edits a paid
|
1249
|
+
# invoice the user unchecks its check box, no +paid+ parameter is sent. So,
|
1250
|
+
# any mass-assignment idiom like
|
1251
|
+
#
|
1252
|
+
# @invoice.update(params[:invoice])
|
1253
|
+
#
|
1254
|
+
# wouldn't update the flag.
|
1255
|
+
#
|
1256
|
+
# To prevent this the helper generates an auxiliary hidden field before
|
1257
|
+
# the very check box. The hidden field has the same name and its
|
1258
|
+
# attributes mimic an unchecked check box.
|
1259
|
+
#
|
1260
|
+
# This way, the client either sends only the hidden field (representing
|
1261
|
+
# the check box is unchecked), or both fields. Since the HTML specification
|
1262
|
+
# says key/value pairs have to be sent in the same order they appear in the
|
1263
|
+
# form, and parameters extraction gets the last occurrence of any repeated
|
1264
|
+
# key in the query string, that works for ordinary forms.
|
1265
|
+
#
|
1266
|
+
# Unfortunately that workaround does not work when the check box goes
|
1267
|
+
# within an array-like parameter, as in
|
1268
|
+
#
|
1269
|
+
# <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
|
1270
|
+
# <%= form.check_box :paid %>
|
1271
|
+
# ...
|
1272
|
+
# <% end %>
|
1273
|
+
#
|
1274
|
+
# because parameter name repetition is precisely what Rails seeks to distinguish
|
1275
|
+
# the elements of the array. For each item with a checked check box you
|
1276
|
+
# get an extra ghost item with only that attribute, assigned to "0".
|
1277
|
+
#
|
1278
|
+
# In that case it is preferable to either use +check_box_tag+ or to use
|
1279
|
+
# hashes instead of arrays.
|
1280
|
+
#
|
1281
|
+
# # Let's say that @post.validated? is 1:
|
1282
|
+
# check_box("post", "validated")
|
1283
|
+
# # => <input name="post[validated]" type="hidden" value="0" />
|
1284
|
+
# # <input checked="checked" type="checkbox" id="post_validated" name="post[validated]" value="1" />
|
1285
|
+
#
|
1286
|
+
# # Let's say that @puppy.gooddog is "no":
|
1287
|
+
# check_box("puppy", "gooddog", {}, "yes", "no")
|
1288
|
+
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
|
1289
|
+
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
|
1290
|
+
#
|
1291
|
+
# check_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
|
1292
|
+
# # => <input name="eula[accepted]" type="hidden" value="no" />
|
1293
|
+
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
|
1294
|
+
def check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
|
1295
|
+
Tags::CheckBox.new(object_name, method, self, checked_value, unchecked_value, options).render
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
# Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
|
1299
|
+
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
|
1300
|
+
# radio button will be checked.
|
1301
|
+
#
|
1302
|
+
# To force the radio button to be checked pass <tt>checked: true</tt> in the
|
1303
|
+
# +options+ hash. You may pass HTML options there as well.
|
1304
|
+
#
|
1305
|
+
# # Let's say that @post.category returns "rails":
|
1306
|
+
# radio_button("post", "category", "rails")
|
1307
|
+
# radio_button("post", "category", "java")
|
1308
|
+
# # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" />
|
1309
|
+
# # <input type="radio" id="post_category_java" name="post[category]" value="java" />
|
1310
|
+
#
|
1311
|
+
# # Let's say that @user.receive_newsletter returns "no":
|
1312
|
+
# radio_button("user", "receive_newsletter", "yes")
|
1313
|
+
# radio_button("user", "receive_newsletter", "no")
|
1314
|
+
# # => <input type="radio" id="user_receive_newsletter_yes" name="user[receive_newsletter]" value="yes" />
|
1315
|
+
# # <input type="radio" id="user_receive_newsletter_no" name="user[receive_newsletter]" value="no" checked="checked" />
|
1316
|
+
def radio_button(object_name, method, tag_value, options = {})
|
1317
|
+
Tags::RadioButton.new(object_name, method, self, tag_value, options).render
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
# Returns a text_field of type "color".
|
1321
|
+
#
|
1322
|
+
# color_field("car", "color")
|
1323
|
+
# # => <input id="car_color" name="car[color]" type="color" value="#000000" />
|
1324
|
+
def color_field(object_name, method, options = {})
|
1325
|
+
Tags::ColorField.new(object_name, method, self, options).render
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
# Returns an input of type "search" for accessing a specified attribute (identified by +method+) on an object
|
1329
|
+
# assigned to the template (identified by +object_name+). Inputs of type "search" may be styled differently by
|
1330
|
+
# some browsers.
|
1331
|
+
#
|
1332
|
+
# search_field(:user, :name)
|
1333
|
+
# # => <input id="user_name" name="user[name]" type="search" />
|
1334
|
+
# search_field(:user, :name, autosave: false)
|
1335
|
+
# # => <input autosave="false" id="user_name" name="user[name]" type="search" />
|
1336
|
+
# search_field(:user, :name, results: 3)
|
1337
|
+
# # => <input id="user_name" name="user[name]" results="3" type="search" />
|
1338
|
+
# # Assume request.host returns "www.example.com"
|
1339
|
+
# search_field(:user, :name, autosave: true)
|
1340
|
+
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" type="search" />
|
1341
|
+
# search_field(:user, :name, onsearch: true)
|
1342
|
+
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
|
1343
|
+
# search_field(:user, :name, autosave: false, onsearch: true)
|
1344
|
+
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
|
1345
|
+
# search_field(:user, :name, autosave: true, onsearch: true)
|
1346
|
+
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" type="search" />
|
1347
|
+
def search_field(object_name, method, options = {})
|
1348
|
+
Tags::SearchField.new(object_name, method, self, options).render
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
# Returns a text_field of type "tel".
|
1352
|
+
#
|
1353
|
+
# telephone_field("user", "phone")
|
1354
|
+
# # => <input id="user_phone" name="user[phone]" type="tel" />
|
1355
|
+
#
|
1356
|
+
def telephone_field(object_name, method, options = {})
|
1357
|
+
Tags::TelField.new(object_name, method, self, options).render
|
1358
|
+
end
|
1359
|
+
# aliases telephone_field
|
1360
|
+
alias phone_field telephone_field
|
1361
|
+
|
1362
|
+
# Returns a text_field of type "date".
|
1363
|
+
#
|
1364
|
+
# date_field("user", "born_on")
|
1365
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" />
|
1366
|
+
#
|
1367
|
+
# The default value is generated by trying to call +strftime+ with "%Y-%m-%d"
|
1368
|
+
# on the object's value, which makes it behave as expected for instances
|
1369
|
+
# of DateTime and ActiveSupport::TimeWithZone. You can still override that
|
1370
|
+
# by passing the "value" option explicitly, e.g.
|
1371
|
+
#
|
1372
|
+
# @user.born_on = Date.new(1984, 1, 27)
|
1373
|
+
# date_field("user", "born_on", value: "1984-05-12")
|
1374
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" value="1984-05-12" />
|
1375
|
+
#
|
1376
|
+
# You can create values for the "min" and "max" attributes by passing
|
1377
|
+
# instances of Date or Time to the options hash.
|
1378
|
+
#
|
1379
|
+
# date_field("user", "born_on", min: Date.today)
|
1380
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" min="2014-05-20" />
|
1381
|
+
#
|
1382
|
+
# Alternatively, you can pass a String formatted as an ISO8601 date as the
|
1383
|
+
# values for "min" and "max."
|
1384
|
+
#
|
1385
|
+
# date_field("user", "born_on", min: "2014-05-20")
|
1386
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" min="2014-05-20" />
|
1387
|
+
#
|
1388
|
+
def date_field(object_name, method, options = {})
|
1389
|
+
Tags::DateField.new(object_name, method, self, options).render
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
# Returns a text_field of type "time".
|
1393
|
+
#
|
1394
|
+
# The default value is generated by trying to call +strftime+ with "%T.%L"
|
1395
|
+
# on the object's value. It is still possible to override that
|
1396
|
+
# by passing the "value" option.
|
1397
|
+
#
|
1398
|
+
# === Options
|
1399
|
+
# * Accepts same options as time_field_tag
|
1400
|
+
#
|
1401
|
+
# === Example
|
1402
|
+
# time_field("task", "started_at")
|
1403
|
+
# # => <input id="task_started_at" name="task[started_at]" type="time" />
|
1404
|
+
#
|
1405
|
+
# You can create values for the "min" and "max" attributes by passing
|
1406
|
+
# instances of Date or Time to the options hash.
|
1407
|
+
#
|
1408
|
+
# time_field("task", "started_at", min: Time.now)
|
1409
|
+
# # => <input id="task_started_at" name="task[started_at]" type="time" min="01:00:00.000" />
|
1410
|
+
#
|
1411
|
+
# Alternatively, you can pass a String formatted as an ISO8601 time as the
|
1412
|
+
# values for "min" and "max."
|
1413
|
+
#
|
1414
|
+
# time_field("task", "started_at", min: "01:00:00")
|
1415
|
+
# # => <input id="task_started_at" name="task[started_at]" type="time" min="01:00:00.000" />
|
1416
|
+
#
|
1417
|
+
def time_field(object_name, method, options = {})
|
1418
|
+
Tags::TimeField.new(object_name, method, self, options).render
|
1419
|
+
end
|
1420
|
+
|
1421
|
+
# Returns a text_field of type "datetime-local".
|
1422
|
+
#
|
1423
|
+
# datetime_field("user", "born_on")
|
1424
|
+
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" />
|
1425
|
+
#
|
1426
|
+
# The default value is generated by trying to call +strftime+ with "%Y-%m-%dT%T"
|
1427
|
+
# on the object's value, which makes it behave as expected for instances
|
1428
|
+
# of DateTime and ActiveSupport::TimeWithZone.
|
1429
|
+
#
|
1430
|
+
# @user.born_on = Date.new(1984, 1, 12)
|
1431
|
+
# datetime_field("user", "born_on")
|
1432
|
+
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" value="1984-01-12T00:00:00" />
|
1433
|
+
#
|
1434
|
+
# You can create values for the "min" and "max" attributes by passing
|
1435
|
+
# instances of Date or Time to the options hash.
|
1436
|
+
#
|
1437
|
+
# datetime_field("user", "born_on", min: Date.today)
|
1438
|
+
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" min="2014-05-20T00:00:00.000" />
|
1439
|
+
#
|
1440
|
+
# Alternatively, you can pass a String formatted as an ISO8601 datetime as
|
1441
|
+
# the values for "min" and "max."
|
1442
|
+
#
|
1443
|
+
# datetime_field("user", "born_on", min: "2014-05-20T00:00:00")
|
1444
|
+
# # => <input id="user_born_on" name="user[born_on]" type="datetime-local" min="2014-05-20T00:00:00.000" />
|
1445
|
+
#
|
1446
|
+
def datetime_field(object_name, method, options = {})
|
1447
|
+
Tags::DatetimeLocalField.new(object_name, method, self, options).render
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
alias datetime_local_field datetime_field
|
1451
|
+
|
1452
|
+
# Returns a text_field of type "month".
|
1453
|
+
#
|
1454
|
+
# month_field("user", "born_on")
|
1455
|
+
# # => <input id="user_born_on" name="user[born_on]" type="month" />
|
1456
|
+
#
|
1457
|
+
# The default value is generated by trying to call +strftime+ with "%Y-%m"
|
1458
|
+
# on the object's value, which makes it behave as expected for instances
|
1459
|
+
# of DateTime and ActiveSupport::TimeWithZone.
|
1460
|
+
#
|
1461
|
+
# @user.born_on = Date.new(1984, 1, 27)
|
1462
|
+
# month_field("user", "born_on")
|
1463
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" value="1984-01" />
|
1464
|
+
#
|
1465
|
+
def month_field(object_name, method, options = {})
|
1466
|
+
Tags::MonthField.new(object_name, method, self, options).render
|
1467
|
+
end
|
1468
|
+
|
1469
|
+
# Returns a text_field of type "week".
|
1470
|
+
#
|
1471
|
+
# week_field("user", "born_on")
|
1472
|
+
# # => <input id="user_born_on" name="user[born_on]" type="week" />
|
1473
|
+
#
|
1474
|
+
# The default value is generated by trying to call +strftime+ with "%Y-W%W"
|
1475
|
+
# on the object's value, which makes it behave as expected for instances
|
1476
|
+
# of DateTime and ActiveSupport::TimeWithZone.
|
1477
|
+
#
|
1478
|
+
# @user.born_on = Date.new(1984, 5, 12)
|
1479
|
+
# week_field("user", "born_on")
|
1480
|
+
# # => <input id="user_born_on" name="user[born_on]" type="date" value="1984-W19" />
|
1481
|
+
#
|
1482
|
+
def week_field(object_name, method, options = {})
|
1483
|
+
Tags::WeekField.new(object_name, method, self, options).render
|
1484
|
+
end
|
1485
|
+
|
1486
|
+
# Returns a text_field of type "url".
|
1487
|
+
#
|
1488
|
+
# url_field("user", "homepage")
|
1489
|
+
# # => <input id="user_homepage" name="user[homepage]" type="url" />
|
1490
|
+
#
|
1491
|
+
def url_field(object_name, method, options = {})
|
1492
|
+
Tags::UrlField.new(object_name, method, self, options).render
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
# Returns a text_field of type "email".
|
1496
|
+
#
|
1497
|
+
# email_field("user", "address")
|
1498
|
+
# # => <input id="user_address" name="user[address]" type="email" />
|
1499
|
+
#
|
1500
|
+
def email_field(object_name, method, options = {})
|
1501
|
+
Tags::EmailField.new(object_name, method, self, options).render
|
1502
|
+
end
|
1503
|
+
|
1504
|
+
# Returns an input tag of type "number".
|
1505
|
+
#
|
1506
|
+
# ==== Options
|
1507
|
+
# * Accepts same options as number_field_tag
|
1508
|
+
def number_field(object_name, method, options = {})
|
1509
|
+
Tags::NumberField.new(object_name, method, self, options).render
|
1510
|
+
end
|
1511
|
+
|
1512
|
+
# Returns an input tag of type "range".
|
1513
|
+
#
|
1514
|
+
# ==== Options
|
1515
|
+
# * Accepts same options as range_field_tag
|
1516
|
+
def range_field(object_name, method, options = {})
|
1517
|
+
Tags::RangeField.new(object_name, method, self, options).render
|
1518
|
+
end
|
1519
|
+
|
1520
|
+
private
|
1521
|
+
def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: !form_with_generates_remote_forms,
|
1522
|
+
skip_enforcing_utf8: false, **options)
|
1523
|
+
html_options = options.slice(:id, :class, :multipart, :method, :data).merge(html)
|
1524
|
+
html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted?
|
1525
|
+
html_options[:enforce_utf8] = !skip_enforcing_utf8
|
1526
|
+
|
1527
|
+
html_options[:enctype] = "multipart/form-data" if html_options.delete(:multipart)
|
1528
|
+
|
1529
|
+
# The following URL is unescaped, this is just a hash of options, and it is the
|
1530
|
+
# responsibility of the caller to escape all the values.
|
1531
|
+
html_options[:action] = url_for(url_for_options || {})
|
1532
|
+
html_options[:"accept-charset"] = "UTF-8"
|
1533
|
+
html_options[:"data-remote"] = true unless local
|
1534
|
+
|
1535
|
+
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
1536
|
+
|
1537
|
+
if !local && html_options[:authenticity_token].blank?
|
1538
|
+
html_options[:authenticity_token] = embed_authenticity_token_in_remote_forms
|
1539
|
+
end
|
1540
|
+
|
1541
|
+
if html_options[:authenticity_token] == true
|
1542
|
+
# Include the default authenticity_token, which is only generated when it's set to nil,
|
1543
|
+
# but we needed the true value to override the default of no authenticity_token on data-remote.
|
1544
|
+
html_options[:authenticity_token] = nil
|
1545
|
+
end
|
1546
|
+
|
1547
|
+
html_options.stringify_keys!
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
def instantiate_builder(record_name, record_object, options)
|
1551
|
+
case record_name
|
1552
|
+
when String, Symbol
|
1553
|
+
object = record_object
|
1554
|
+
object_name = record_name
|
1555
|
+
else
|
1556
|
+
object = record_name
|
1557
|
+
object_name = model_name_from_record_or_class(object).param_key if object
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
builder = options[:builder] || default_form_builder_class
|
1561
|
+
builder.new(object_name, object, self, options)
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
def default_form_builder_class
|
1565
|
+
builder = default_form_builder || ActionView::Base.default_form_builder
|
1566
|
+
builder.respond_to?(:constantize) ? builder.constantize : builder
|
1567
|
+
end
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
# A +FormBuilder+ object is associated with a particular model object and
|
1571
|
+
# allows you to generate fields associated with the model object. The
|
1572
|
+
# +FormBuilder+ object is yielded when using +form_for+ or +fields_for+.
|
1573
|
+
# For example:
|
1574
|
+
#
|
1575
|
+
# <%= form_for @person do |person_form| %>
|
1576
|
+
# Name: <%= person_form.text_field :name %>
|
1577
|
+
# Admin: <%= person_form.check_box :admin %>
|
1578
|
+
# <% end %>
|
1579
|
+
#
|
1580
|
+
# In the above block, a +FormBuilder+ object is yielded as the
|
1581
|
+
# +person_form+ variable. This allows you to generate the +text_field+
|
1582
|
+
# and +check_box+ fields by specifying their eponymous methods, which
|
1583
|
+
# modify the underlying template and associates the <tt>@person</tt> model object
|
1584
|
+
# with the form.
|
1585
|
+
#
|
1586
|
+
# The +FormBuilder+ object can be thought of as serving as a proxy for the
|
1587
|
+
# methods in the +FormHelper+ module. This class, however, allows you to
|
1588
|
+
# call methods with the model object you are building the form for.
|
1589
|
+
#
|
1590
|
+
# You can create your own custom FormBuilder templates by subclassing this
|
1591
|
+
# class. For example:
|
1592
|
+
#
|
1593
|
+
# class MyFormBuilder < ActionView::Helpers::FormBuilder
|
1594
|
+
# def div_radio_button(method, tag_value, options = {})
|
1595
|
+
# @template.content_tag(:div,
|
1596
|
+
# @template.radio_button(
|
1597
|
+
# @object_name, method, tag_value, objectify_options(options)
|
1598
|
+
# )
|
1599
|
+
# )
|
1600
|
+
# end
|
1601
|
+
# end
|
1602
|
+
#
|
1603
|
+
# The above code creates a new method +div_radio_button+ which wraps a div
|
1604
|
+
# around the new radio button. Note that when options are passed in, you
|
1605
|
+
# must call +objectify_options+ in order for the model object to get
|
1606
|
+
# correctly passed to the method. If +objectify_options+ is not called,
|
1607
|
+
# then the newly created helper will not be linked back to the model.
|
1608
|
+
#
|
1609
|
+
# The +div_radio_button+ code from above can now be used as follows:
|
1610
|
+
#
|
1611
|
+
# <%= form_for @person, :builder => MyFormBuilder do |f| %>
|
1612
|
+
# I am a child: <%= f.div_radio_button(:admin, "child") %>
|
1613
|
+
# I am an adult: <%= f.div_radio_button(:admin, "adult") %>
|
1614
|
+
# <% end -%>
|
1615
|
+
#
|
1616
|
+
# The standard set of helper methods for form building are located in the
|
1617
|
+
# +field_helpers+ class attribute.
|
1618
|
+
class FormBuilder
|
1619
|
+
include ModelNaming
|
1620
|
+
|
1621
|
+
# The methods which wrap a form helper call.
|
1622
|
+
class_attribute :field_helpers, default: [
|
1623
|
+
:fields_for, :fields, :label, :text_field, :password_field,
|
1624
|
+
:hidden_field, :file_field, :text_area, :check_box,
|
1625
|
+
:radio_button, :color_field, :search_field,
|
1626
|
+
:telephone_field, :phone_field, :date_field,
|
1627
|
+
:time_field, :datetime_field, :datetime_local_field,
|
1628
|
+
:month_field, :week_field, :url_field, :email_field,
|
1629
|
+
:number_field, :range_field
|
1630
|
+
]
|
1631
|
+
|
1632
|
+
attr_accessor :object_name, :object, :options
|
1633
|
+
|
1634
|
+
attr_reader :multipart, :index
|
1635
|
+
alias :multipart? :multipart
|
1636
|
+
|
1637
|
+
def multipart=(multipart)
|
1638
|
+
@multipart = multipart
|
1639
|
+
|
1640
|
+
if parent_builder = @options[:parent_builder]
|
1641
|
+
parent_builder.multipart = multipart
|
1642
|
+
end
|
1643
|
+
end
|
1644
|
+
|
1645
|
+
def self._to_partial_path
|
1646
|
+
@_to_partial_path ||= name.demodulize.underscore.sub!(/_builder$/, "")
|
1647
|
+
end
|
1648
|
+
|
1649
|
+
def to_partial_path
|
1650
|
+
self.class._to_partial_path
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
def to_model
|
1654
|
+
self
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
def initialize(object_name, object, template, options)
|
1658
|
+
@nested_child_index = {}
|
1659
|
+
@object_name, @object, @template, @options = object_name, object, template, options
|
1660
|
+
@default_options = @options ? @options.slice(:index, :namespace, :skip_default_ids, :allow_method_names_outside_object) : {}
|
1661
|
+
@default_html_options = @default_options.except(:skip_default_ids, :allow_method_names_outside_object)
|
1662
|
+
|
1663
|
+
convert_to_legacy_options(@options)
|
1664
|
+
|
1665
|
+
if @object_name.to_s.match(/\[\]$/)
|
1666
|
+
if (object ||= @template.instance_variable_get("@#{Regexp.last_match.pre_match}")) && object.respond_to?(:to_param)
|
1667
|
+
@auto_index = object.to_param
|
1668
|
+
else
|
1669
|
+
raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
|
1670
|
+
end
|
1671
|
+
end
|
1672
|
+
|
1673
|
+
@multipart = nil
|
1674
|
+
@index = options[:index] || options[:child_index]
|
1675
|
+
end
|
1676
|
+
|
1677
|
+
(field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
|
1678
|
+
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
1679
|
+
def #{selector}(method, options = {}) # def text_field(method, options = {})
|
1680
|
+
@template.send( # @template.send(
|
1681
|
+
#{selector.inspect}, # "text_field",
|
1682
|
+
@object_name, # @object_name,
|
1683
|
+
method, # method,
|
1684
|
+
objectify_options(options)) # objectify_options(options))
|
1685
|
+
end # end
|
1686
|
+
RUBY_EVAL
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
# Creates a scope around a specific model object like form_for, but
|
1690
|
+
# doesn't create the form tags themselves. This makes fields_for suitable
|
1691
|
+
# for specifying additional model objects in the same form.
|
1692
|
+
#
|
1693
|
+
# Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
|
1694
|
+
# its method signature is slightly different. Like +form_for+, it yields
|
1695
|
+
# a FormBuilder object associated with a particular model object to a block,
|
1696
|
+
# and within the block allows methods to be called on the builder to
|
1697
|
+
# generate fields associated with the model object. Fields may reflect
|
1698
|
+
# a model object in two ways - how they are named (hence how submitted
|
1699
|
+
# values appear within the +params+ hash in the controller) and what
|
1700
|
+
# default values are shown when the form the fields appear in is first
|
1701
|
+
# displayed. In order for both of these features to be specified independently,
|
1702
|
+
# both an object name (represented by either a symbol or string) and the
|
1703
|
+
# object itself can be passed to the method separately -
|
1704
|
+
#
|
1705
|
+
# <%= form_for @person do |person_form| %>
|
1706
|
+
# First name: <%= person_form.text_field :first_name %>
|
1707
|
+
# Last name : <%= person_form.text_field :last_name %>
|
1708
|
+
#
|
1709
|
+
# <%= fields_for :permission, @person.permission do |permission_fields| %>
|
1710
|
+
# Admin? : <%= permission_fields.check_box :admin %>
|
1711
|
+
# <% end %>
|
1712
|
+
#
|
1713
|
+
# <%= person_form.submit %>
|
1714
|
+
# <% end %>
|
1715
|
+
#
|
1716
|
+
# In this case, the checkbox field will be represented by an HTML +input+
|
1717
|
+
# tag with the +name+ attribute <tt>permission[admin]</tt>, and the submitted
|
1718
|
+
# value will appear in the controller as <tt>params[:permission][:admin]</tt>.
|
1719
|
+
# If <tt>@person.permission</tt> is an existing record with an attribute
|
1720
|
+
# +admin+, the initial state of the checkbox when first displayed will
|
1721
|
+
# reflect the value of <tt>@person.permission.admin</tt>.
|
1722
|
+
#
|
1723
|
+
# Often this can be simplified by passing just the name of the model
|
1724
|
+
# object to +fields_for+ -
|
1725
|
+
#
|
1726
|
+
# <%= fields_for :permission do |permission_fields| %>
|
1727
|
+
# Admin?: <%= permission_fields.check_box :admin %>
|
1728
|
+
# <% end %>
|
1729
|
+
#
|
1730
|
+
# ...in which case, if <tt>:permission</tt> also happens to be the name of an
|
1731
|
+
# instance variable <tt>@permission</tt>, the initial state of the input
|
1732
|
+
# field will reflect the value of that variable's attribute <tt>@permission.admin</tt>.
|
1733
|
+
#
|
1734
|
+
# Alternatively, you can pass just the model object itself (if the first
|
1735
|
+
# argument isn't a string or symbol +fields_for+ will realize that the
|
1736
|
+
# name has been omitted) -
|
1737
|
+
#
|
1738
|
+
# <%= fields_for @person.permission do |permission_fields| %>
|
1739
|
+
# Admin?: <%= permission_fields.check_box :admin %>
|
1740
|
+
# <% end %>
|
1741
|
+
#
|
1742
|
+
# and +fields_for+ will derive the required name of the field from the
|
1743
|
+
# _class_ of the model object, e.g. if <tt>@person.permission</tt>, is
|
1744
|
+
# of class +Permission+, the field will still be named <tt>permission[admin]</tt>.
|
1745
|
+
#
|
1746
|
+
# Note: This also works for the methods in FormOptionsHelper and
|
1747
|
+
# DateHelper that are designed to work with an object as base, like
|
1748
|
+
# FormOptionsHelper#collection_select and DateHelper#datetime_select.
|
1749
|
+
#
|
1750
|
+
# === Nested Attributes Examples
|
1751
|
+
#
|
1752
|
+
# When the object belonging to the current scope has a nested attribute
|
1753
|
+
# writer for a certain attribute, fields_for will yield a new scope
|
1754
|
+
# for that attribute. This allows you to create forms that set or change
|
1755
|
+
# the attributes of a parent object and its associations in one go.
|
1756
|
+
#
|
1757
|
+
# Nested attribute writers are normal setter methods named after an
|
1758
|
+
# association. The most common way of defining these writers is either
|
1759
|
+
# with +accepts_nested_attributes_for+ in a model definition or by
|
1760
|
+
# defining a method with the proper name. For example: the attribute
|
1761
|
+
# writer for the association <tt>:address</tt> is called
|
1762
|
+
# <tt>address_attributes=</tt>.
|
1763
|
+
#
|
1764
|
+
# Whether a one-to-one or one-to-many style form builder will be yielded
|
1765
|
+
# depends on whether the normal reader method returns a _single_ object
|
1766
|
+
# or an _array_ of objects.
|
1767
|
+
#
|
1768
|
+
# ==== One-to-one
|
1769
|
+
#
|
1770
|
+
# Consider a Person class which returns a _single_ Address from the
|
1771
|
+
# <tt>address</tt> reader method and responds to the
|
1772
|
+
# <tt>address_attributes=</tt> writer method:
|
1773
|
+
#
|
1774
|
+
# class Person
|
1775
|
+
# def address
|
1776
|
+
# @address
|
1777
|
+
# end
|
1778
|
+
#
|
1779
|
+
# def address_attributes=(attributes)
|
1780
|
+
# # Process the attributes hash
|
1781
|
+
# end
|
1782
|
+
# end
|
1783
|
+
#
|
1784
|
+
# This model can now be used with a nested fields_for, like so:
|
1785
|
+
#
|
1786
|
+
# <%= form_for @person do |person_form| %>
|
1787
|
+
# ...
|
1788
|
+
# <%= person_form.fields_for :address do |address_fields| %>
|
1789
|
+
# Street : <%= address_fields.text_field :street %>
|
1790
|
+
# Zip code: <%= address_fields.text_field :zip_code %>
|
1791
|
+
# <% end %>
|
1792
|
+
# ...
|
1793
|
+
# <% end %>
|
1794
|
+
#
|
1795
|
+
# When address is already an association on a Person you can use
|
1796
|
+
# +accepts_nested_attributes_for+ to define the writer method for you:
|
1797
|
+
#
|
1798
|
+
# class Person < ActiveRecord::Base
|
1799
|
+
# has_one :address
|
1800
|
+
# accepts_nested_attributes_for :address
|
1801
|
+
# end
|
1802
|
+
#
|
1803
|
+
# If you want to destroy the associated model through the form, you have
|
1804
|
+
# to enable it first using the <tt>:allow_destroy</tt> option for
|
1805
|
+
# +accepts_nested_attributes_for+:
|
1806
|
+
#
|
1807
|
+
# class Person < ActiveRecord::Base
|
1808
|
+
# has_one :address
|
1809
|
+
# accepts_nested_attributes_for :address, allow_destroy: true
|
1810
|
+
# end
|
1811
|
+
#
|
1812
|
+
# Now, when you use a form element with the <tt>_destroy</tt> parameter,
|
1813
|
+
# with a value that evaluates to +true+, you will destroy the associated
|
1814
|
+
# model (eg. 1, '1', true, or 'true'):
|
1815
|
+
#
|
1816
|
+
# <%= form_for @person do |person_form| %>
|
1817
|
+
# ...
|
1818
|
+
# <%= person_form.fields_for :address do |address_fields| %>
|
1819
|
+
# ...
|
1820
|
+
# Delete: <%= address_fields.check_box :_destroy %>
|
1821
|
+
# <% end %>
|
1822
|
+
# ...
|
1823
|
+
# <% end %>
|
1824
|
+
#
|
1825
|
+
# ==== One-to-many
|
1826
|
+
#
|
1827
|
+
# Consider a Person class which returns an _array_ of Project instances
|
1828
|
+
# from the <tt>projects</tt> reader method and responds to the
|
1829
|
+
# <tt>projects_attributes=</tt> writer method:
|
1830
|
+
#
|
1831
|
+
# class Person
|
1832
|
+
# def projects
|
1833
|
+
# [@project1, @project2]
|
1834
|
+
# end
|
1835
|
+
#
|
1836
|
+
# def projects_attributes=(attributes)
|
1837
|
+
# # Process the attributes hash
|
1838
|
+
# end
|
1839
|
+
# end
|
1840
|
+
#
|
1841
|
+
# Note that the <tt>projects_attributes=</tt> writer method is in fact
|
1842
|
+
# required for fields_for to correctly identify <tt>:projects</tt> as a
|
1843
|
+
# collection, and the correct indices to be set in the form markup.
|
1844
|
+
#
|
1845
|
+
# When projects is already an association on Person you can use
|
1846
|
+
# +accepts_nested_attributes_for+ to define the writer method for you:
|
1847
|
+
#
|
1848
|
+
# class Person < ActiveRecord::Base
|
1849
|
+
# has_many :projects
|
1850
|
+
# accepts_nested_attributes_for :projects
|
1851
|
+
# end
|
1852
|
+
#
|
1853
|
+
# This model can now be used with a nested fields_for. The block given to
|
1854
|
+
# the nested fields_for call will be repeated for each instance in the
|
1855
|
+
# collection:
|
1856
|
+
#
|
1857
|
+
# <%= form_for @person do |person_form| %>
|
1858
|
+
# ...
|
1859
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
1860
|
+
# <% if project_fields.object.active? %>
|
1861
|
+
# Name: <%= project_fields.text_field :name %>
|
1862
|
+
# <% end %>
|
1863
|
+
# <% end %>
|
1864
|
+
# ...
|
1865
|
+
# <% end %>
|
1866
|
+
#
|
1867
|
+
# It's also possible to specify the instance to be used:
|
1868
|
+
#
|
1869
|
+
# <%= form_for @person do |person_form| %>
|
1870
|
+
# ...
|
1871
|
+
# <% @person.projects.each do |project| %>
|
1872
|
+
# <% if project.active? %>
|
1873
|
+
# <%= person_form.fields_for :projects, project do |project_fields| %>
|
1874
|
+
# Name: <%= project_fields.text_field :name %>
|
1875
|
+
# <% end %>
|
1876
|
+
# <% end %>
|
1877
|
+
# <% end %>
|
1878
|
+
# ...
|
1879
|
+
# <% end %>
|
1880
|
+
#
|
1881
|
+
# Or a collection to be used:
|
1882
|
+
#
|
1883
|
+
# <%= form_for @person do |person_form| %>
|
1884
|
+
# ...
|
1885
|
+
# <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
|
1886
|
+
# Name: <%= project_fields.text_field :name %>
|
1887
|
+
# <% end %>
|
1888
|
+
# ...
|
1889
|
+
# <% end %>
|
1890
|
+
#
|
1891
|
+
# If you want to destroy any of the associated models through the
|
1892
|
+
# form, you have to enable it first using the <tt>:allow_destroy</tt>
|
1893
|
+
# option for +accepts_nested_attributes_for+:
|
1894
|
+
#
|
1895
|
+
# class Person < ActiveRecord::Base
|
1896
|
+
# has_many :projects
|
1897
|
+
# accepts_nested_attributes_for :projects, allow_destroy: true
|
1898
|
+
# end
|
1899
|
+
#
|
1900
|
+
# This will allow you to specify which models to destroy in the
|
1901
|
+
# attributes hash by adding a form element for the <tt>_destroy</tt>
|
1902
|
+
# parameter with a value that evaluates to +true+
|
1903
|
+
# (eg. 1, '1', true, or 'true'):
|
1904
|
+
#
|
1905
|
+
# <%= form_for @person do |person_form| %>
|
1906
|
+
# ...
|
1907
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
1908
|
+
# Delete: <%= project_fields.check_box :_destroy %>
|
1909
|
+
# <% end %>
|
1910
|
+
# ...
|
1911
|
+
# <% end %>
|
1912
|
+
#
|
1913
|
+
# When a collection is used you might want to know the index of each
|
1914
|
+
# object into the array. For this purpose, the <tt>index</tt> method
|
1915
|
+
# is available in the FormBuilder object.
|
1916
|
+
#
|
1917
|
+
# <%= form_for @person do |person_form| %>
|
1918
|
+
# ...
|
1919
|
+
# <%= person_form.fields_for :projects do |project_fields| %>
|
1920
|
+
# Project #<%= project_fields.index %>
|
1921
|
+
# ...
|
1922
|
+
# <% end %>
|
1923
|
+
# ...
|
1924
|
+
# <% end %>
|
1925
|
+
#
|
1926
|
+
# Note that fields_for will automatically generate a hidden field
|
1927
|
+
# to store the ID of the record. There are circumstances where this
|
1928
|
+
# hidden field is not needed and you can pass <tt>include_id: false</tt>
|
1929
|
+
# to prevent fields_for from rendering it automatically.
|
1930
|
+
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
|
1931
|
+
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
|
1932
|
+
fields_options[:builder] ||= options[:builder]
|
1933
|
+
fields_options[:namespace] = options[:namespace]
|
1934
|
+
fields_options[:parent_builder] = self
|
1935
|
+
|
1936
|
+
case record_name
|
1937
|
+
when String, Symbol
|
1938
|
+
if nested_attributes_association?(record_name)
|
1939
|
+
return fields_for_with_nested_attributes(record_name, record_object, fields_options, block)
|
1940
|
+
end
|
1941
|
+
else
|
1942
|
+
record_object = record_name.is_a?(Array) ? record_name.last : record_name
|
1943
|
+
record_name = model_name_from_record_or_class(record_object).param_key
|
1944
|
+
end
|
1945
|
+
|
1946
|
+
object_name = @object_name
|
1947
|
+
index = if options.has_key?(:index)
|
1948
|
+
options[:index]
|
1949
|
+
elsif defined?(@auto_index)
|
1950
|
+
object_name = object_name.to_s.sub(/\[\]$/, "")
|
1951
|
+
@auto_index
|
1952
|
+
end
|
1953
|
+
|
1954
|
+
record_name = if index
|
1955
|
+
"#{object_name}[#{index}][#{record_name}]"
|
1956
|
+
elsif record_name.to_s.end_with?("[]")
|
1957
|
+
record_name = record_name.to_s.sub(/(.*)\[\]$/, "[\\1][#{record_object.id}]")
|
1958
|
+
"#{object_name}#{record_name}"
|
1959
|
+
else
|
1960
|
+
"#{object_name}[#{record_name}]"
|
1961
|
+
end
|
1962
|
+
fields_options[:child_index] = index
|
1963
|
+
|
1964
|
+
@template.fields_for(record_name, record_object, fields_options, &block)
|
1965
|
+
end
|
1966
|
+
|
1967
|
+
# See the docs for the <tt>ActionView::FormHelper.fields</tt> helper method.
|
1968
|
+
def fields(scope = nil, model: nil, **options, &block)
|
1969
|
+
options[:allow_method_names_outside_object] = true
|
1970
|
+
options[:skip_default_ids] = !FormHelper.form_with_generates_ids
|
1971
|
+
|
1972
|
+
convert_to_legacy_options(options)
|
1973
|
+
|
1974
|
+
fields_for(scope || model, model, **options, &block)
|
1975
|
+
end
|
1976
|
+
|
1977
|
+
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object
|
1978
|
+
# assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation
|
1979
|
+
# is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly.
|
1980
|
+
# Additional options on the label tag can be passed as a hash with +options+. These options will be tagged
|
1981
|
+
# onto the HTML as an HTML element attribute as in the example shown, except for the <tt>:value</tt> option, which is designed to
|
1982
|
+
# target labels for radio_button tags (where the value is used in the ID of the input tag).
|
1983
|
+
#
|
1984
|
+
# ==== Examples
|
1985
|
+
# label(:title)
|
1986
|
+
# # => <label for="post_title">Title</label>
|
1987
|
+
#
|
1988
|
+
# You can localize your labels based on model and attribute names.
|
1989
|
+
# For example you can define the following in your locale (e.g. en.yml)
|
1990
|
+
#
|
1991
|
+
# helpers:
|
1992
|
+
# label:
|
1993
|
+
# post:
|
1994
|
+
# body: "Write your entire text here"
|
1995
|
+
#
|
1996
|
+
# Which then will result in
|
1997
|
+
#
|
1998
|
+
# label(:body)
|
1999
|
+
# # => <label for="post_body">Write your entire text here</label>
|
2000
|
+
#
|
2001
|
+
# Localization can also be based purely on the translation of the attribute-name
|
2002
|
+
# (if you are using ActiveRecord):
|
2003
|
+
#
|
2004
|
+
# activerecord:
|
2005
|
+
# attributes:
|
2006
|
+
# post:
|
2007
|
+
# cost: "Total cost"
|
2008
|
+
#
|
2009
|
+
# label(:cost)
|
2010
|
+
# # => <label for="post_cost">Total cost</label>
|
2011
|
+
#
|
2012
|
+
# label(:title, "A short title")
|
2013
|
+
# # => <label for="post_title">A short title</label>
|
2014
|
+
#
|
2015
|
+
# label(:title, "A short title", class: "title_label")
|
2016
|
+
# # => <label for="post_title" class="title_label">A short title</label>
|
2017
|
+
#
|
2018
|
+
# label(:privacy, "Public Post", value: "public")
|
2019
|
+
# # => <label for="post_privacy_public">Public Post</label>
|
2020
|
+
#
|
2021
|
+
# label(:terms) do
|
2022
|
+
# raw('Accept <a href="/terms">Terms</a>.')
|
2023
|
+
# end
|
2024
|
+
# # => <label for="post_terms">Accept <a href="/terms">Terms</a>.</label>
|
2025
|
+
def label(method, text = nil, options = {}, &block)
|
2026
|
+
@template.label(@object_name, method, text, objectify_options(options), &block)
|
2027
|
+
end
|
2028
|
+
|
2029
|
+
# Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object
|
2030
|
+
# assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object.
|
2031
|
+
# It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked.
|
2032
|
+
# Additional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1
|
2033
|
+
# while the default +unchecked_value+ is set to 0 which is convenient for boolean values.
|
2034
|
+
#
|
2035
|
+
# ==== Gotcha
|
2036
|
+
#
|
2037
|
+
# The HTML specification says unchecked check boxes are not successful, and
|
2038
|
+
# thus web browsers do not send them. Unfortunately this introduces a gotcha:
|
2039
|
+
# if an +Invoice+ model has a +paid+ flag, and in the form that edits a paid
|
2040
|
+
# invoice the user unchecks its check box, no +paid+ parameter is sent. So,
|
2041
|
+
# any mass-assignment idiom like
|
2042
|
+
#
|
2043
|
+
# @invoice.update(params[:invoice])
|
2044
|
+
#
|
2045
|
+
# wouldn't update the flag.
|
2046
|
+
#
|
2047
|
+
# To prevent this the helper generates an auxiliary hidden field before
|
2048
|
+
# the very check box. The hidden field has the same name and its
|
2049
|
+
# attributes mimic an unchecked check box.
|
2050
|
+
#
|
2051
|
+
# This way, the client either sends only the hidden field (representing
|
2052
|
+
# the check box is unchecked), or both fields. Since the HTML specification
|
2053
|
+
# says key/value pairs have to be sent in the same order they appear in the
|
2054
|
+
# form, and parameters extraction gets the last occurrence of any repeated
|
2055
|
+
# key in the query string, that works for ordinary forms.
|
2056
|
+
#
|
2057
|
+
# Unfortunately that workaround does not work when the check box goes
|
2058
|
+
# within an array-like parameter, as in
|
2059
|
+
#
|
2060
|
+
# <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
|
2061
|
+
# <%= form.check_box :paid %>
|
2062
|
+
# ...
|
2063
|
+
# <% end %>
|
2064
|
+
#
|
2065
|
+
# because parameter name repetition is precisely what Rails seeks to distinguish
|
2066
|
+
# the elements of the array. For each item with a checked check box you
|
2067
|
+
# get an extra ghost item with only that attribute, assigned to "0".
|
2068
|
+
#
|
2069
|
+
# In that case it is preferable to either use +check_box_tag+ or to use
|
2070
|
+
# hashes instead of arrays.
|
2071
|
+
#
|
2072
|
+
# # Let's say that @post.validated? is 1:
|
2073
|
+
# check_box("validated")
|
2074
|
+
# # => <input name="post[validated]" type="hidden" value="0" />
|
2075
|
+
# # <input checked="checked" type="checkbox" id="post_validated" name="post[validated]" value="1" />
|
2076
|
+
#
|
2077
|
+
# # Let's say that @puppy.gooddog is "no":
|
2078
|
+
# check_box("gooddog", {}, "yes", "no")
|
2079
|
+
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
|
2080
|
+
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
|
2081
|
+
#
|
2082
|
+
# # Let's say that @eula.accepted is "no":
|
2083
|
+
# check_box("accepted", { class: 'eula_check' }, "yes", "no")
|
2084
|
+
# # => <input name="eula[accepted]" type="hidden" value="no" />
|
2085
|
+
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
|
2086
|
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
2087
|
+
@template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
|
2088
|
+
end
|
2089
|
+
|
2090
|
+
# Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
|
2091
|
+
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
|
2092
|
+
# radio button will be checked.
|
2093
|
+
#
|
2094
|
+
# To force the radio button to be checked pass <tt>checked: true</tt> in the
|
2095
|
+
# +options+ hash. You may pass HTML options there as well.
|
2096
|
+
#
|
2097
|
+
# # Let's say that @post.category returns "rails":
|
2098
|
+
# radio_button("category", "rails")
|
2099
|
+
# radio_button("category", "java")
|
2100
|
+
# # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" />
|
2101
|
+
# # <input type="radio" id="post_category_java" name="post[category]" value="java" />
|
2102
|
+
#
|
2103
|
+
# # Let's say that @user.receive_newsletter returns "no":
|
2104
|
+
# radio_button("receive_newsletter", "yes")
|
2105
|
+
# radio_button("receive_newsletter", "no")
|
2106
|
+
# # => <input type="radio" id="user_receive_newsletter_yes" name="user[receive_newsletter]" value="yes" />
|
2107
|
+
# # <input type="radio" id="user_receive_newsletter_no" name="user[receive_newsletter]" value="no" checked="checked" />
|
2108
|
+
def radio_button(method, tag_value, options = {})
|
2109
|
+
@template.radio_button(@object_name, method, tag_value, objectify_options(options))
|
2110
|
+
end
|
2111
|
+
|
2112
|
+
# Returns a hidden input tag tailored for accessing a specified attribute (identified by +method+) on an object
|
2113
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
2114
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
2115
|
+
# shown.
|
2116
|
+
#
|
2117
|
+
# ==== Examples
|
2118
|
+
# # Let's say that @signup.pass_confirm returns true:
|
2119
|
+
# hidden_field(:pass_confirm)
|
2120
|
+
# # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="true" />
|
2121
|
+
#
|
2122
|
+
# # Let's say that @post.tag_list returns "blog, ruby":
|
2123
|
+
# hidden_field(:tag_list)
|
2124
|
+
# # => <input type="hidden" id="post_tag_list" name="post[tag_list]" value="blog, ruby" />
|
2125
|
+
#
|
2126
|
+
# # Let's say that @user.token returns "abcde":
|
2127
|
+
# hidden_field(:token)
|
2128
|
+
# # => <input type="hidden" id="user_token" name="user[token]" value="abcde" />
|
2129
|
+
#
|
2130
|
+
def hidden_field(method, options = {})
|
2131
|
+
@emitted_hidden_id = true if method == :id
|
2132
|
+
@template.hidden_field(@object_name, method, objectify_options(options))
|
2133
|
+
end
|
2134
|
+
|
2135
|
+
# Returns a file upload input tag tailored for accessing a specified attribute (identified by +method+) on an object
|
2136
|
+
# assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
|
2137
|
+
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
|
2138
|
+
# shown.
|
2139
|
+
#
|
2140
|
+
# Using this method inside a +form_for+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
|
2141
|
+
#
|
2142
|
+
# ==== Options
|
2143
|
+
# * Creates standard HTML attributes for the tag.
|
2144
|
+
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
|
2145
|
+
# * <tt>:multiple</tt> - If set to true, *in most updated browsers* the user will be allowed to select multiple files.
|
2146
|
+
# * <tt>:accept</tt> - If set to one or multiple mime-types, the user will be suggested a filter when choosing a file. You still need to set up model validations.
|
2147
|
+
#
|
2148
|
+
# ==== Examples
|
2149
|
+
# # Let's say that @user has avatar:
|
2150
|
+
# file_field(:avatar)
|
2151
|
+
# # => <input type="file" id="user_avatar" name="user[avatar]" />
|
2152
|
+
#
|
2153
|
+
# # Let's say that @post has image:
|
2154
|
+
# file_field(:image, :multiple => true)
|
2155
|
+
# # => <input type="file" id="post_image" name="post[image][]" multiple="multiple" />
|
2156
|
+
#
|
2157
|
+
# # Let's say that @post has attached:
|
2158
|
+
# file_field(:attached, accept: 'text/html')
|
2159
|
+
# # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
|
2160
|
+
#
|
2161
|
+
# # Let's say that @post has image:
|
2162
|
+
# file_field(:image, accept: 'image/png,image/gif,image/jpeg')
|
2163
|
+
# # => <input type="file" id="post_image" name="post[image]" accept="image/png,image/gif,image/jpeg" />
|
2164
|
+
#
|
2165
|
+
# # Let's say that @attachment has file:
|
2166
|
+
# file_field(:file, class: 'file_input')
|
2167
|
+
# # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
|
2168
|
+
def file_field(method, options = {})
|
2169
|
+
self.multipart = true
|
2170
|
+
@template.file_field(@object_name, method, objectify_options(options))
|
2171
|
+
end
|
2172
|
+
|
2173
|
+
# Add the submit button for the given form. When no value is given, it checks
|
2174
|
+
# if the object is a new resource or not to create the proper label:
|
2175
|
+
#
|
2176
|
+
# <%= form_for @post do |f| %>
|
2177
|
+
# <%= f.submit %>
|
2178
|
+
# <% end %>
|
2179
|
+
#
|
2180
|
+
# In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
|
2181
|
+
# submit button label; otherwise, it uses "Update Post".
|
2182
|
+
#
|
2183
|
+
# Those labels can be customized using I18n under the +helpers.submit+ key and using
|
2184
|
+
# <tt>%{model}</tt> for translation interpolation:
|
2185
|
+
#
|
2186
|
+
# en:
|
2187
|
+
# helpers:
|
2188
|
+
# submit:
|
2189
|
+
# create: "Create a %{model}"
|
2190
|
+
# update: "Confirm changes to %{model}"
|
2191
|
+
#
|
2192
|
+
# It also searches for a key specific to the given object:
|
2193
|
+
#
|
2194
|
+
# en:
|
2195
|
+
# helpers:
|
2196
|
+
# submit:
|
2197
|
+
# post:
|
2198
|
+
# create: "Add %{model}"
|
2199
|
+
#
|
2200
|
+
def submit(value = nil, options = {})
|
2201
|
+
value, options = nil, value if value.is_a?(Hash)
|
2202
|
+
value ||= submit_default_value
|
2203
|
+
@template.submit_tag(value, options)
|
2204
|
+
end
|
2205
|
+
|
2206
|
+
# Add the submit button for the given form. When no value is given, it checks
|
2207
|
+
# if the object is a new resource or not to create the proper label:
|
2208
|
+
#
|
2209
|
+
# <%= form_for @post do |f| %>
|
2210
|
+
# <%= f.button %>
|
2211
|
+
# <% end %>
|
2212
|
+
#
|
2213
|
+
# In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
|
2214
|
+
# button label; otherwise, it uses "Update Post".
|
2215
|
+
#
|
2216
|
+
# Those labels can be customized using I18n under the +helpers.submit+ key
|
2217
|
+
# (the same as submit helper) and using <tt>%{model}</tt> for translation interpolation:
|
2218
|
+
#
|
2219
|
+
# en:
|
2220
|
+
# helpers:
|
2221
|
+
# submit:
|
2222
|
+
# create: "Create a %{model}"
|
2223
|
+
# update: "Confirm changes to %{model}"
|
2224
|
+
#
|
2225
|
+
# It also searches for a key specific to the given object:
|
2226
|
+
#
|
2227
|
+
# en:
|
2228
|
+
# helpers:
|
2229
|
+
# submit:
|
2230
|
+
# post:
|
2231
|
+
# create: "Add %{model}"
|
2232
|
+
#
|
2233
|
+
# ==== Examples
|
2234
|
+
# button("Create post")
|
2235
|
+
# # => <button name='button' type='submit'>Create post</button>
|
2236
|
+
#
|
2237
|
+
# button do
|
2238
|
+
# content_tag(:strong, 'Ask me!')
|
2239
|
+
# end
|
2240
|
+
# # => <button name='button' type='submit'>
|
2241
|
+
# # <strong>Ask me!</strong>
|
2242
|
+
# # </button>
|
2243
|
+
#
|
2244
|
+
def button(value = nil, options = {}, &block)
|
2245
|
+
value, options = nil, value if value.is_a?(Hash)
|
2246
|
+
value ||= submit_default_value
|
2247
|
+
@template.button_tag(value, options, &block)
|
2248
|
+
end
|
2249
|
+
|
2250
|
+
def emitted_hidden_id?
|
2251
|
+
@emitted_hidden_id ||= nil
|
2252
|
+
end
|
2253
|
+
|
2254
|
+
private
|
2255
|
+
def objectify_options(options)
|
2256
|
+
@default_options.merge(options.merge(object: @object))
|
2257
|
+
end
|
2258
|
+
|
2259
|
+
def submit_default_value
|
2260
|
+
object = convert_to_model(@object)
|
2261
|
+
key = object ? (object.persisted? ? :update : :create) : :submit
|
2262
|
+
|
2263
|
+
model = if object.respond_to?(:model_name)
|
2264
|
+
object.model_name.human
|
2265
|
+
else
|
2266
|
+
@object_name.to_s.humanize
|
2267
|
+
end
|
2268
|
+
|
2269
|
+
defaults = []
|
2270
|
+
defaults << :"helpers.submit.#{object_name}.#{key}"
|
2271
|
+
defaults << :"helpers.submit.#{key}"
|
2272
|
+
defaults << "#{key.to_s.humanize} #{model}"
|
2273
|
+
|
2274
|
+
I18n.t(defaults.shift, model: model, default: defaults)
|
2275
|
+
end
|
2276
|
+
|
2277
|
+
def nested_attributes_association?(association_name)
|
2278
|
+
@object.respond_to?("#{association_name}_attributes=")
|
2279
|
+
end
|
2280
|
+
|
2281
|
+
def fields_for_with_nested_attributes(association_name, association, options, block)
|
2282
|
+
name = "#{object_name}[#{association_name}_attributes]"
|
2283
|
+
association = convert_to_model(association)
|
2284
|
+
|
2285
|
+
if association.respond_to?(:persisted?)
|
2286
|
+
association = [association] if @object.send(association_name).respond_to?(:to_ary)
|
2287
|
+
elsif !association.respond_to?(:to_ary)
|
2288
|
+
association = @object.send(association_name)
|
2289
|
+
end
|
2290
|
+
|
2291
|
+
if association.respond_to?(:to_ary)
|
2292
|
+
explicit_child_index = options[:child_index]
|
2293
|
+
output = ActiveSupport::SafeBuffer.new
|
2294
|
+
association.each do |child|
|
2295
|
+
if explicit_child_index
|
2296
|
+
options[:child_index] = explicit_child_index.call if explicit_child_index.respond_to?(:call)
|
2297
|
+
else
|
2298
|
+
options[:child_index] = nested_child_index(name)
|
2299
|
+
end
|
2300
|
+
output << fields_for_nested_model("#{name}[#{options[:child_index]}]", child, options, block)
|
2301
|
+
end
|
2302
|
+
output
|
2303
|
+
elsif association
|
2304
|
+
fields_for_nested_model(name, association, options, block)
|
2305
|
+
end
|
2306
|
+
end
|
2307
|
+
|
2308
|
+
def fields_for_nested_model(name, object, fields_options, block)
|
2309
|
+
object = convert_to_model(object)
|
2310
|
+
emit_hidden_id = object.persisted? && fields_options.fetch(:include_id) {
|
2311
|
+
options.fetch(:include_id, true)
|
2312
|
+
}
|
2313
|
+
|
2314
|
+
@template.fields_for(name, object, fields_options) do |f|
|
2315
|
+
output = @template.capture(f, &block)
|
2316
|
+
output.concat f.hidden_field(:id) if output && emit_hidden_id && !f.emitted_hidden_id?
|
2317
|
+
output
|
2318
|
+
end
|
2319
|
+
end
|
2320
|
+
|
2321
|
+
def nested_child_index(name)
|
2322
|
+
@nested_child_index[name] ||= -1
|
2323
|
+
@nested_child_index[name] += 1
|
2324
|
+
end
|
2325
|
+
|
2326
|
+
def convert_to_legacy_options(options)
|
2327
|
+
if options.key?(:skip_id)
|
2328
|
+
options[:include_id] = !options.delete(:skip_id)
|
2329
|
+
end
|
2330
|
+
end
|
2331
|
+
end
|
2332
|
+
end
|
2333
|
+
|
2334
|
+
ActiveSupport.on_load(:action_view) do
|
2335
|
+
cattr_accessor :default_form_builder, instance_writer: false, instance_reader: false, default: ::ActionView::Helpers::FormBuilder
|
2336
|
+
end
|
2337
|
+
end
|