Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

router.rb match and :format problem

#6134

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.

Reported by Todor Dragnev · December 8th, 2010 @ 05:34 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh
    • Importance changed from to Low

    In routes pass :format => false and then use your regexp to match the incoming data.

    December 8th, 2010 @ 06:04 PM

  2. Todor Dragnev
    Todor Dragnev

    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.

    December 8th, 2010 @ 07:08 PM

  3. Andrew White
    Andrew White
    • 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.

    February 9th, 2011 @ 06:48 AM