3

I'm new to rails...

I try to send such string as :search param: "55.675155, 21.833466" and 2 as :id param... But something is bad...

i get No route matches [GET] "/exchanger_lists/get_exchangers_via_coordinates/.....

My route file:

  match 'exchanger_lists/get_exchangers_via_coordinates/:search,:id' => 'exchanger_lists#get_exchangers_via_coordinates'

But also how then url must look in browser???

How to do this in Rails way? I read doc's, but something is not clear on 100% (

Just how to configure my route and how to call from browser?

Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47
  • 2
    Do you have exchanger_lists controller with method get_exchangers_via_coordinates?. Try slash instead of comma: `:search/:id` I don't know is that's a problem but a comma there is not standard inside an URL – sites May 04 '13 at 12:04
  • @juanpastas yes i have, all is ok working if i pass in url something like exchanger_lists/get_exchangers_via_coordinates/535,1 but with string (dots, comma) is bad. Also your solution didn't help – Valdis Azamaris May 04 '13 at 12:10
  • maybe this could help you: http://devblog.avdi.org/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-insane/ – Matthias May 04 '13 at 12:21

2 Answers2

3
match 'exchanger_lists/get_exchangers_via_coordinates/:search,:id' => 'exchanger_lists#get_exchangers_via_coordinates', 
constraints: { search: /[^\/]+/ }

From here

Community
  • 1
  • 1
sites
  • 21,417
  • 17
  • 87
  • 146
  • just i change to 'exchanger_lists/get_exchangers_via_coordinates/:search/:distance' all is ok, but when i try to send distance as float (for example 0.5) something is bad... – Valdis Azamaris May 04 '13 at 12:45
  • 1
    do the same for distance `constraints: { search: /[^\/]+/, distance: /[^\/]+/ }` – sites May 04 '13 at 12:47
  • heh, wait.... but how to be if i call a json view? if i write .... .json it didn't understand – Valdis Azamaris May 04 '13 at 15:28
  • maybe something like? distance: /[^\/]+(?=\.html\z|\.json\z)/ but how to be when .html is by default not writen? if empty - then html, if added .json then json – Valdis Azamaris May 04 '13 at 15:47
  • You have to write a regexp that matches `5.5` in `5.5.json` `/[^\/]+?(?!.*..json)/`. I could not understand that regexp :p – sites May 04 '13 at 15:54
  • is not working as must do.... Look: .html - could be, but could be empty(than render html page), but also i could have .json (then render json). Now your /[^\/]+?(?!.*..json)/ is working strange)) if i enter /53.674239,%2023.828101/0.1 i get nothing(invalid param is getting to method), but if write /53.674239,%2023.828101/0.1.html all is ok, also with json all is ok – Valdis Azamaris May 04 '13 at 16:02
  • You should ask for a regular expression in another question, that one was difficult for me. for `5.5` should match `5.5` for `5.5.(json|html)` should match `5.5` – sites May 05 '13 at 02:16
0

You could change your routes like following:

 match 'exchanger_lists/get_exchangers_via_coordinates/:x/:y/:id' => 'exchanger_lists#get_exchangers_via_coordinates'

params[:x] and params[:y] will hold your coordinates. I think this is more beautiful code, than holding the to coordinates in one param.

Matthias
  • 4,355
  • 2
  • 25
  • 34