Can a mobile mime type fall back to “html” in Rails?

后端 未结 15 1349
余生分开走
余生分开走 2020-12-23 22:17

I\'m using this code (taken from here) in ApplicationController to detect iPhone, iPod Touch and iPad requests:

before_filter :detect_mobile_request, :detec         


        
15条回答
  •  长情又很酷
    2020-12-23 22:45

    You can in this case for the format to html. By example you want always use the html in user show method

    class UserController
    
      def show
        ..your_code..
        render :show, :format => :html
      end
    end
    

    In this case, if you request show on User controller you render all the time the html version.

    If you want render JSON too by example you can made some test about your type like :

    class UserController
    
      def show
        ..your_code..
        if [:mobile, :tablet, :html].include?(request.format)
          render :show, :format => :html
        else
          respond_with(@user)
        end
      end
    
    end
    

提交回复
热议问题