Www.address.com/data?number=1&number2&number3

Hi,

Any ideas how to get the the numbers from the url in the subject? That
is sent as a POST but all the parameters have the same name. I can only
get the last number of the params.

What’s the trick?

Thanks.

Sorry the request is:

www.address.com/data?number=1&number=2&number=3

Hi

. I can only get the last number of the params.

Yes that is true.You have to modify the view? Please paste the view
code

Sijo

Hi Sijo,

Not really doing anything with the view actually. I just need to get
those in the controller and reply with some data back to the client.

This is part of a public spec that tells that a request like that should
be sent to the server and the server should do something with it.

I know that if the request would be:
www.address.com/data?number[]=1&number[]=2&number[]=3

Then I could easily get the values of the numbers, but that wouldn’t be
following the spec and cause interoperability issues.

Any ideas how I could set a rule in routes.rb so I could interpret this
problematic url?

Regards.

Hi

I think you have to look at Route Globbing in rails. It also deals
with arrays.Please check this

http://api.rubyonrails.org/classes/ActionController/Routing.html

Sijo

Thanks Sijo,

I actually found that by using any of these on the controller:

request.query_string
request.request_uri
request.url

I can get the whole clean request. So after some parsing I should be
able to extract the params myself. A bit ugly but I can live with it at
this point.

Thanks!

comopasta Gr wrote:

Hi,

Any ideas how to get the the numbers from the url in the subject? That
is sent as a POST but all the parameters have the same name. I can only
get the last number of the params.

What’s the trick?

Thanks.

Hi comopasta,

One simple solution is pass them as a comma separated string.

instead of

www.address.com/data?number=1&number=2&number=3

have it like this

www.address.com/data?number=1,2,3

and from the controller take it to an array

@numbers = params[:number].split(‘,’)

a quick and dirty solution :smiley:

cheers,
sameera

Hi,

Yeah that would be an option. The big problem is that there is a OMA
spec that tells that the request SHALL come in the form of
www.address.com/data?number=1&number=2&number=3

So that is the way how the request will come. It cannot be changed.
In any case I solved the issue and can now get all the params and more
:slight_smile:

Thanks!