This project is archived and is in readonly mode.

#4810 ✓invalid
Cedric Fung

Responder dosen't care params[:format]

Reported by Cedric Fung | June 9th, 2010 @ 05:09 PM

I have some code like this

before_filter :detect_browser

def detect_browser
  params[:format] = 'mobile' if request.headers["HTTP_USER_AGENT"].match(MOBILE_BROWSERS)
end

in rails 3.0beta3, it works OK and will responde with params[:format]

e.g.
if params[:format] is mobile, then the controller will render show.mobile.erb

but in beta4, the controller just ignores params[:format]

Comments and changes to this ticket

  • Neeraj Singh

    Neeraj Singh June 10th, 2010 @ 06:39 PM

    I get xml output when I visit http://localhost:3000/users with following code. I am using rails master.

    class UsersController < ApplicationController
      before_filter :detect_browser
      def detect_browser
        params[:format] = 'xml'
      end
    
      def index
        @users = User.all
        respond_to do |format|
          format.html # index.html.erb
          format.xml  { render :xml => @users }
        end
      end
    end
    

    Could it be that if condition is not working in your case?

  • Cedric Fung

    Cedric Fung June 11th, 2010 @ 03:49 AM

    but I use new responder syntax in rails 3

    class UsersController < ApplicationController
      respond_to :html, :mobile
      
      def index
        @users = User.all
        respond_with(@users)
      end
    end
    
    it dosen't work with rails master
    
  • Neeraj Singh

    Neeraj Singh June 11th, 2010 @ 04:36 AM

    It's working for me with following code

    class UsersController < ApplicationController
    
      respond_to :html, :xml
    
      before_filter :detect_browser
    
      def detect_browser
        params[:format] = 'xml'
      end
    
      def index
        @users = User.all
      end
    
    end
    

    I see index.html.erb if I comment out filter. With filter on I see index.xml.erb while visiting /users .

  • Cedric Fung

    Cedric Fung June 11th, 2010 @ 04:56 AM

    It won't work, my log output

    this from beta3

    ======================================
    params[:format] = xml
    ======================================
    Processing by UsersController#index as XML
    

    this from rails master

     Processing by UsersController#index as HTML
    ======================================
    params[:format] = xml
    ======================================
    

    It just processes before params[:format]

  • José Valim

    José Valim June 22nd, 2010 @ 04:19 PM

    Please try to add a failing test case in Rails test suite.

  • Neeraj Singh

    Neeraj Singh July 18th, 2010 @ 03:37 PM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

    I am not able to reproduce it.

    @Cedric if you are able to reproduce it then please provide information so that we can reproduce it.

    I am marking it as 'invalid'. However it can be reopened later if sufficient information is provided.

  • Ryan Bigg

    Ryan Bigg October 11th, 2010 @ 10:54 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages