ruby-on-railsrubyruby-on-rails-3

request.fullpath with no parameters


request.fullpath gives the fullpath plus any parameter passed, such as

/page?param1=value&param2&value

How can I get just the page with no params? Like

/page

Thank you.


Solution

  • Use path instead of fullpath.

    Although not documented, request.path worked for me. I usually use my plugin rails_web_console for playing with the request object.

    Update (2025):

    ActionDispatch::Request includes the Rack::Request::Helpers module, which provides the path method. Here's the source code for the path method:

    def path
      script_name + path_info
    end