Skip to content

Instantly share code, notes, and snippets.

@tillsc
Created November 10, 2010 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tillsc/670562 to your computer and use it in GitHub Desktop.
Save tillsc/670562 to your computer and use it in GitHub Desktop.
Add this to your ApplicationController to get a linking data style url handling (force usage of 'format' in URLs)
before_filter :ensure_extension
# Force an extension to every url. (LD)
def ensure_extension
redirect_to url_for(:format => (request.format && request.format.symbol) || :html) unless params[:format]
end
# Set a default value for the :format parameter in url_for and *_url/*_path methods.
def default_url_options(options = nil)
{:format => params[:format]}.merge(options || {})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment