Reputation: 33755
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?
Upvotes: 0
Views: 1155
Reputation: 9693
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] =~ /.*/ }
Upvotes: 1