<commit_before>= FallbackRouter

An Rails engine that can be used to specify fallback routing rules, which will be evaluated last (lowest priority).
This is useful for catch-all routes that should execute *after* all other engines.

FallbackRouter has been tested on Rails 4.0, but should work on later 4.x versions as well.

== Usage

In your Gemfile, add the engine as the *LAST* gem:

  gem 'fallback_router', github: 'markwpiper/fallback_router'


In your routes.rb, mount the engine as the *LAST* entry:

  mount FallbackRouter::Engine => '/'
  FallbackRouter::Engine.routes.draw do
    # Your fallback routes go here.
    # Note that helpers and routes will be included in your regular application namespace / module
    # (This is because isolate_namespace is intentionally not called for this engine)
  end


== Rack Interactions

FallbackRouter will be last in the Rails precendence order, but depending on your Rack setup and middleware you have loaded, there may stil be routes provided by these plugins that are accidentally masked by FallbackRouter.

It is important to use the <tt>:constraints</tt> option on your fallback routing rules to allow these requests to get routed to the right place.

eg: To allow OmniAuth Rack middleware to still work, you might add <tt>:constraints => lambda {|request| !request.path.include?("/auth/") }</tt> to your route.


== Example

As a full example of how to setup your application's routes.rb, here is how to load the routes for the excellent Comfortable Mexican Sofa CMS as a fallback engine at the root of your site, and exclude mucking w/ any Rack-level Omni-auth routes:

  mount FallbackRouter::Engine => '/'<commit_msg>Add readme info on synthesize_head_routes<commit_after>= FallbackRouter

An Rails engine that can be used to specify fallback routing rules, which will be evaluated last (lowest priority).
This is useful for catch-all routes that should execute *after* all other engines.

FallbackRouter has been tested on Rails 4.0, but should work on later 4.x versions as well.

== Usage

In your Gemfile, add the engine as the *LAST* gem:

  gem 'fallback_router', github: 'markwpiper/fallback_router'


In your routes.rb, mount the engine as the *LAST* entry:

  mount FallbackRouter::Engine => '/'
  FallbackRouter::Engine.routes.draw do
    # Your fallback routes go here.
    # Note that helpers and routes will be included in your regular application namespace / module
    # (This is because isolate_namespace is intentionally not called for this engine)
  end


== Routing HEAD Requests

Some versions of Rails 4.x require a workaround for a Rails bug with HEAD request routing when using an engine mounted at '/'.

In these problematic versions, implicitly generated HEAD routes are not prioritized high enough in the Rails routing table to be routed correctly, and will be accidentally routed to the mounted engine instead of the application.

To workaround this issue, call <tt>synthesize_head_routes</tt> with your application's route set before mounting the FallbackRouter.


== Rack Interactions

FallbackRouter will be last in the Rails precendence order, but depending on your Rack setup and middleware you have loaded, there may stil be routes provided by these plugins that are accidentally masked by FallbackRouter.

It is important to use the <tt>:constraints</tt> option on your fallback routing rules to allow these requests to get routed to the right place.

eg: To allow OmniAuth Rack middleware to still work, you might add <tt>:constraints => lambda {|request| !request.path.include?("/auth/") }</tt> to your route.


== Example

As a full example of how to setup your application's routes.rb, here is how to load the routes for the excellent Comfortable Mexican Sofa CMS as a fallback engine at the root of your site, and exclude mucking w/ any Rack-level Omni-auth routes:

  # NOTE: You may need to call synthesize_head_routes if you are on a version of Rails that doesn't route HEAD requests correctly!
  # synthesize_head_routes MyRailsProjectName::Application.routes

  mount FallbackRouter::Engine => '/'
{'fraction_non_alphanumeric': 0.05800633682671216, 'fraction_numerical': 0.0017060687301974165, 'mean_word_length': 4.457446808510638, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2424077', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1042, 'n_words': 576}