0

The last line in my routes.rb is this:

resources :tags, path: "", except: [:index, :new, :create], constraints: { :id => /.*/ }

Which basically handles all /tagnames.

The issue is I am trying to use livereload, the rack middleware version and what is happening is that it is sending a ping to /livereload.

But, the above route intercepts it and sends it to my TagsController....so my log file looks like this:

Started GET "/livereload" for 192.168.1.1 at 2013-03-30 19:49:13 -0500
Processing by TagsController#show as HTML
  Parameters: {"id"=>"livereload"}
  Tag Load (3.3ms)  SELECT "tags".* FROM "tags" WHERE "tags"."name" = 'livereload' LIMIT 1
  Tag Load (2.0ms)  SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT 1  [["id", "livereload"]]
Completed 404 Not Found in 9ms

ActiveRecord::RecordNotFound (Couldn't find Tag with id=livereload):
  app/controllers/tags_controller.rb:16:in `show'

So how do I either tell that route to ignore all /livereload requests or how do I handle this another way?

marcamillion
  • 32,933
  • 55
  • 189
  • 380

1 Answers1

1

You can use a custom constraint on your route to tell to ignore any special route, since its a simple rule you can do it inline, you can check for req.env["PATH_INFO"] or you you can also check for req.params[:id]

example 1:

resources :tags, path: "", except: [:index, :new, :create], constraints: lambda{ |req| req.env['PATH_INFO'] != '/livereload' && req.params[:id] =~ /.*/ }

example 2:

resources :tags, path: "", except: [:index, :new, :create], constraints: lambda{ |req| req.params[:id] != '/livereload' && req.params[:id] =~ /.*/ }
rorra
  • 9,593
  • 3
  • 39
  • 61
  • By the way....both of these don't work. I still get `ActionController::RoutingError (No route matches [GET] "/livereload"):` – marcamillion Mar 31 '13 at 18:24
  • That's a different problem. Regarding the constraint, the idea is the same, you can use the constraint to make sure that the route won't trap the livereload, for what you wrote, its working fine, you can try with !req.params[:id].include?('livereload'). Now you are getting "ActionController::RoutingError" because there is not route that matches the "/livereload", check your livereload configuration, for some reason, the route by the middleware is not being generated. – rorra Mar 31 '13 at 19:12