开发者

request.fullpath with no parameters

开发者 https://www.devze.com 2023-02-15 22:20 出处:网络
r开发者_如何转开发equest.fullpath gives the fullpath plus any parameter passed, such as /page?param1=value&param2&value

r开发者_如何转开发equest.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.


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:

As noticed by turboladen, "[ActionDispatch::Request][2] inherits from [Rack::Request‌][3]​, where request.path is defined".

path is not documented there, but the source displays script_name + path_info.


what about a simple split:

request.fullpath.split("?")[0]


no need for splitting,

request.path_info

gives you just that


regular expression

request.fullpath.gsub( /\?.*/, "" )
0

精彩评论

暂无评论...
验证码 换一张
取 消