title: undefined method `request_uri' ActionDispatch
body: <p>i want to create a mobile version of my website</p>
  
  <p>i want when someone visit my site from mobile device it will redirect him to a subdomain m.mywebsite.com </p>
  
  <p>but there is a choice to go to the full site that is stored in cookies</p>
  
  <p>here is my config</p>
  
  <p>app/controllers/application_controller.rb:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    # Prevent CSRF attacks by raising an exception.
    # For APIs, you may want to use :null_session instead.
    protect_from_forgery with: :exception
  
    before_filter :set_mobile_preferences
    before_filter :redirect_to_mobile_if_applicable
    before_filter :prepend_view_path_if_mobile
  
    private
  
      def not_authenticated
        flash[:warning] = 'You have to authenticate to access this page.'
        redirect_to login_path
      end
  
      def expirated_reset_token
        redirect_to root_path
      end
  
    # mobile subdomain 
      def set_mobile_preferences
          if params[:mobile_site]
            cookies.delete(:prefer_full_site)
          elsif params[:full_site]
            cookies.permanent[:prefer_full_site] = 1
            redirect_to_full_site if mobile_request?
          end
      end
  
      def prepend_view_path_if_mobile
          if mobile_request?
            prepend_view_path Rails.root + 'app' + 'mobile_views'
          end
      end
  
      def redirect_to_full_site
          redirect_to request.protocol + request.host_with_port.gsub(/^m\./, '') +
                      request.request_uri and return
      end
  
      def redirect_to_mobile_if_applicable
          unless mobile_request? || cookies[:prefer_full_site] || !mobile_browser?
            redirect_to request.protocol + "m." + request.host_with_port.gsub(/^www\./, '') +
                        request.request_uri and return
          end
      end
  
      def mobile_request?
          request.subdomains.first == 'm'
      end
  
      helper_method :mobile_request?
  
      def mobile_browser?
          request.env["HTTP_USER_AGENT"] &amp;&amp; request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad|Android)/]
        end
      helper_method :mobile_browser?
  
  end
  </code></pre>
  
  <p>the problem is when i visit</p>
  
  <pre><code>http://m.mywebsite.com/?full_site=1
  </code></pre>
  
  <p>it give me </p>
  
  <pre><code>undefined method `request_uri' for #&lt;ActionDispatch::Request:0x007fdb60fa8a00&gt; Did you mean? request_parameters
  </code></pre>
  
  <p>please help</p>