Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails, how to get params from url string? [duplicate]

Possible Duplicate:
How do I easily parse a URL with parameters in a Rails test?

sorry for my english...

I have in my archives.rb model a method to get all src attributes from a html content, I am getting src's like:

http://localhost:3000/es/editor/archives/28/show_image?x=142&y=142

I need to get the params from that url, specifically: id, x, y

Thanks, Regards.

like image 795
el_quick Avatar asked Aug 10 '11 14:08

el_quick


2 Answers

The correct approach :

url = "http://localhost:3000/es/editor/archives/28/show_image?x=142&y=142"
uri = URI::parse(url)
id = uri.path.split('/')[4]
params = CGI::parse(uri.query)
like image 65
DGM Avatar answered Oct 04 '22 04:10

DGM


In your controller you can do 'params[:x]' and 'params[:y]'. For example:

x = params[:x]
y = params[:y]
like image 38
thenengah Avatar answered Oct 04 '22 02:10

thenengah