rails 3, how add a view that does not use same layout as rest of app?

前端 未结 5 1055
醉话见心
醉话见心 2020-12-07 08:30

I could not find any docs or examples on how to structure my app to allow different views in the same controller to use completely different layouts and stylesheets.

5条回答
  •  渐次进展
    2020-12-07 09:25

    Well, if it's a different view for mobile devices but all desktop versions are the same then you could use JQtouch.

    http://railscasts.com/episodes/199-mobile-devices

    # config/initializers/mime_types.rb
    Mime::Type.register_alias "text/html", :mobile
    
    # application_controller.rb
    before_filter :prepare_for_mobile
    
    private
    
    def mobile_device?
      if session[:mobile_param]
        session[:mobile_param] == "1"
      else
        request.user_agent =~ /Mobile|webOS/
      end
    end
    helper_method :mobile_device?
    
    def prepare_for_mobile
      session[:mobile_param] = params[:mobile] if params[:mobile]
      request.format = :mobile if mobile_device?
    end
    

    The above code is taken from the Railscasts example.

提交回复
热议问题