Created
November 16, 2011 23:52
-
-
Save lukeholder/1371911 to your computer and use it in GitHub Desktop.
rails segment request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routes: | |
match '*segments' => 'RumaRequest#out' | |
request url: | |
http://rumaengine.dev/ds/dsa/dsa?fds=fds | |
class RumaRequestController < ApplicationController | |
def out | |
path = (params[:path] || request.fullpath).clone # TODO: params[:path] is more consistent | |
path = path.split('?').first # take everything before the query string or the lookup fails | |
path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '') # remove the page extension | |
path.gsub!(/^\//, '') # remove the leading slash | |
path = 'index' if path.blank? | |
# The above does the path segments detection (figuring out with templates to parse). | |
path_detection = "Ruma Request path detection #{path}" | |
# This is just using the routes splat | |
path_from_segment = "Ruma Request through rails route #{params['segments']}" | |
render :text => "#{path_detection} <br/> #{path_from_segment}" | |
end | |
end | |
outputs: | |
Ruma Request path detection ds/dsa/dsa | |
Ruma Request through rails route ds/dsa/dsa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment