Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Responder dosen't care params[:format]

#4810

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]

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh

    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?

    June 10th, 2010 @ 06:39 PM

  2. Cedric Fung
    Cedric Fung

    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
    

    June 11th, 2010 @ 03:49 AM

  3. Neeraj Singh
    Neeraj Singh

    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 .

    June 11th, 2010 @ 04:36 AM

  4. Cedric Fung
    Cedric Fung

    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]

    June 11th, 2010 @ 04:56 AM

  5. José Valim
    José Valim

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

    June 22nd, 2010 @ 04:19 PM

  6. Neeraj Singh
    Neeraj Singh
    • 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.

    July 18th, 2010 @ 03:37 PM

  7. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 11th, 2010 @ 10:54 AM

  8. bingbing