1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/dispatch
Łukasz Strzałkowski 2d3a6a0cb8 Action Pack Variants
By default, variants in the templates will be picked up if a variant is set
and there's a match. The format will be:

  app/views/projects/show.html.erb
  app/views/projects/show.html+tablet.erb
  app/views/projects/show.html+phone.erb

If request.variant = :tablet is set, we'll automatically be rendering the
html+tablet template.

In the controller, we can also tailer to the variants with this syntax:

  class ProjectsController < ActionController::Base
    def show
      respond_to do |format|
        format.html do |html|
          @stars = @project.stars

          html.tablet { @notifications = @project.notifications }
          html.phone  { @chat_heads    = @project.chat_heads }
        end

        format.js
        format.atom
      end
    end
  end

The variant itself is nil by default, but can be set in before filters, like
so:

  class ApplicationController < ActionController::Base
    before_action do
      if request.user_agent =~ /iPad/
        request.variant = :tablet
      end
    end
  end

This is modeled loosely on custom mime types, but it's specifically not
intended to be used together. If you're going to make a custom mime type,
you don't need a variant. Variants are for variations on a single mime
types.
2013-12-04 00:13:16 +01:00
..
middleware_stack
request Deep Munge the parameters for GET and POST 2013-12-02 16:44:27 -08:00
routing Build fix for Routing Inspector 2013-11-22 00:45:51 +01:00
session
callbacks_test.rb
cookies_test.rb
debug_exceptions_test.rb Revert "Merge pull request #9660 from sebasoga/change_strong_parameters_require_behaviour" 2013-11-02 14:30:03 -05:00
header_test.rb
live_response_test.rb
mapper_test.rb
middleware_stack_test.rb
mime_type_test.rb Remove Mime::Type#verify_request? and Mime::Type.browser_generated_types were deprecated. 2013-06-02 00:07:58 +09:00
mount_test.rb Don't remove trailing slash from PATH_INFO for mounted apps 2013-06-21 08:56:19 +02:00
prefix_generation_test.rb Respect SCRIPT_NAME when using redirect with a relative path 2013-10-10 13:03:26 +01:00
rack_cache_test.rb
rack_test.rb Remove Mime::Type#verify_request? and Mime::Type.browser_generated_types were deprecated. 2013-06-02 00:07:58 +09:00
reloader_test.rb
request_id_test.rb
request_test.rb Action Pack Variants 2013-12-04 00:13:16 +01:00
response_test.rb update Rails::Railtie::Configuration and ActionDispatch::Response#respond_to? to accept include_private argument 2013-08-16 08:22:08 -07:00
routing_assertions_test.rb
routing_test.rb Try to escape each part of a path redirect route correctly 2013-12-02 05:16:05 +00:00
show_exceptions_test.rb Merge pull request #9857 from yyyc514/bad_params_should_400 2013-04-30 17:38:56 -07:00
ssl_test.rb Space is not required for Set-Cookie header 2013-07-05 15:40:14 +09:00
static_test.rb skiping => skipping 2013-11-19 03:08:08 +05:30
test_request_test.rb Allow overriding of all headers from passed environment hash 2013-07-25 07:54:57 +01:00
test_response_test.rb
uploaded_file_test.rb
url_generation_test.rb