Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Variant negotiation #14043

Merged
merged 1 commit into from Feb 13, 2014

Conversation

Projects
None yet
3 participants
Member

lukaszx0 commented Feb 13, 2014

Allow setting request.variant as an array - an order in which they will be rendered.

For example:

request.variant = [:tablet, :phone]

respond_to do |format|
  format.html.none
  format.html.phone # this gets rendered
end

/cc @dhh @jeremy

Variant negotiation
Allow setting `request.variant` as an array - an order in which they will be
rendered.

For example:

  request.variant = [:tablet, :phone]

  respond_to do |format|
    format.html.none
    format.html.phone # this gets rendered
  end

@lukaszx0 lukaszx0 self-assigned this Feb 13, 2014

dhh added a commit that referenced this pull request Feb 13, 2014

@dhh dhh merged commit f2dfa83 into rails:master Feb 13, 2014

1 check passed

default The Travis CI build passed
Details

@lukaszx0 lukaszx0 deleted the lukaszx0:variants-negotiation branch Feb 13, 2014

@carlosantoniodasilva carlosantoniodasilva commented on the diff Feb 13, 2014

actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -68,10 +68,12 @@ def formats
# Sets the \variant for template.
def variant=(variant)
- if variant.is_a? Symbol
+ if variant.is_a?(Symbol)
+ @variant = [variant]
+ elsif variant.is_a?(Array)
@variant = variant
@carlosantoniodasilva

carlosantoniodasilva Feb 13, 2014

Owner

What's the point of validating an Array if we don't guarantee it contains only symbols?

@lukaszx0

lukaszx0 Feb 13, 2014

Member

Valid point, I guess I need to add symbolize_keys! here. I'll send PR with fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment