Skip to content

Instantly share code, notes, and snippets.

@lukeholder
Created November 16, 2011 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeholder/1371911 to your computer and use it in GitHub Desktop.
Save lukeholder/1371911 to your computer and use it in GitHub Desktop.
rails segment request
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