This project is archived and is in readonly mode.
router.rb match and :format problem
Reported by Todor Dragnev | December 8th, 2010 @ 05:34 PM
I have following request via method GET:
http://localhost:3000/check/car/8C9BB87/43.21335/27.9023316666667/1...
So information from this request grouped in this way:
:controler - check :action - car :uniqid - 8C9BB87 :latitude - 43.21335 :longitude - 27.9023316666667 :timestamp - 1291808804 :seq - 3
I wrote the following match rule in routes.rb:
match "check/car/:car_number/:gps_location_latitude/:gps_location_longitude/:gps_location_timestamp/:seq", :controller => :check, :action => :car
Output from rake routes:
/check/car/:car_number/:gps_location_latitude/:gps_location_longitude/:gps_location_timestamp/:images_count(.:format) {:action=>"car", :controller=>"check"}
but when try to hit this controller
curl http://localhost:3000/check/car/8C9BB87/4321.335/279023316.666667/1291808804/3
I receive:
No route matches /check/car/8C9BB87/4321.335/279023316.666667/1291808804/3
When I remove '.' from url all is ok, the problem seems to be in :format, but i don't know how to avoid or disable :format checking.
Comments and changes to this ticket
-
Neeraj Singh December 8th, 2010 @ 06:04 PM
- Importance changed from to Low
In routes pass :format => false and then use your regexp to match the incoming data.
-
Todor Dragnev December 8th, 2010 @ 07:08 PM
Ok, I change my route to
match "check/car/:car_number/:latitude/:longitude/:timestamp/:images_count",
:controller => :check, :action => :car, :format => false
Output from rake routes is:
/check/car/:car_number/:latitude/:longitude/:timestamp/:images_count {:action=>"car", :controller=>"check"}
Then execute test command still have error:
curl http://localhost:3000/check/car/MC89B/4313046/27.901795/12.91830451/2
No route matches /check/car/MC89B/4313046/27.901795/12.91830451/2
When remove dots from request
curl http://localhost:3000/check/car/MC89B/4313046/27901795/1291830451/2
All is Ok.
-
Andrew White February 9th, 2011 @ 06:48 AM
- State changed from new to invalid
Todor, by default . is not allowed in dynamic segments - you need to supply a regexp to override this:
get '/location/:lat/:lng', :to => 'maps#show', :lat => %r{[^/]+}, :lng => %r{[^/]+}, :format => false
This crops up frequently - see my response to #5994. I really must get around to adding something to the guides.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 6126 path helper problem Similar to #6134 ?