The Extension filter chops a file extension off from the end of the recognized path. When a path is generated the filter re-adds the extension to the path accordingly.
incoming url: /products.xml filtered url: /products generated url: /products.xml
You can install the filter like this:
# in config/routes.rb Rails.application.routes.draw do filter :extension end
The Locale filter extracts segments matching /:locale from the beginning of the recognized path and exposes the page parameter as params. When a path is generated the filter adds the segments to the path accordingly if the page parameter is passed to the url helper.
incoming url: /de/products filtered url: /products params: params[:locale] = 'de'
You can install the filter like this:
# in config/routes.rb Rails.application.routes.draw do filter :locale end
To make your named_route helpers or url_for add the locale segments you can use:
products_path(:locale => 'de') url_for(:products, :locale => 'de'))
The Pagination filter extracts segments matching /page/:page from the end of the recognized url and exposes the page parameter as params. When a url is generated the filter adds the segments to the url accordingly if the page parameter is passed to the url helper.
incoming url: /products/page/1 filtered url: /products params: params[:page] = 1
You can install the filter like this:
# in config/routes.rb Rails.application.routes.draw do filter :pagination end
To make your named_route helpers or url_for add the pagination segments you can use:
products_path(:page => 1) url_for(:products, :page => 1)
The Uuid filter extracts an UUID segment from the beginning of the recognized path and exposes the page parameter as params. When a path is generated the filter adds the segments to the path accordingly if the page parameter is passed to the url helper.
incoming url: /d00fbbd1-82b6-4c1a-a57d-098d529d6854/products filtered url: /products params: params[:uuid] = 'd00fbbd1-82b6-4c1a-a57d-098d529d6854'
You can install the filter like this:
# in config/routes.rb Rails.application.routes.draw do filter :uuid end
To make your named_route helpers or url_for add the uuid segment you can use:
products_path(:uuid => uuid) url_for(:products, :uuid => uuid)
# File lib/routing_filter.rb, line 17 def active=(active) @@active = active end
# File lib/routing_filter/filters/locale.rb, line 61 def around_generate(*args, &block) params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en) locale = params.delete(:locale) # extract the passed :locale option locale = I18n.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false) locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid args << params yield.tap do |result| url = result.is_a?(Array) ? result.first : result prepend_segment!(result, locale) if prepend_locale?(locale) && !excluded?(url) end
# File lib/routing_filter/filters/extension.rb, line 49 def append_extension!(url) url.replace url.sub(/(\?|$)/, ".#{extension}\\1") end
# File lib/routing_filter/filters/extension.rb, line 45 def append_extension?(url) !(blank?(url) || excluded?(url) || mime_extension?(url)) end
# File lib/routing_filter/filters/extension.rb, line 53 def blank?(url) url.blank? || !!url.match(%(^/(\?|$))) end
# File lib/routing_filter/filters/extension.rb, line 57 def excluded?(url) case exclude when Regexp url =~ exclude when Proc exclude.call(url) end end
Generated with the Darkfish Rdoc Generator 2.