How Get some specific value from Rails string? -


i want specific value string of rails below these 2 string.

 1. "http://localhost:3000/admin/shops/assign_shoes?id=50&page=1"   2. "http://localhost:3000/admin/shops/assign_shoes?id=50" 

i need value of "id" "50". don't matter how many parameters in string

as query string.

actually these strings values of request.referer

any efficient method?

thanks

there several different ways this, common way know parsing string using uri class, , making use of cgi class extract query params, so:

uri = uri.parse(request.referer) parsed_query = cgi::parse(uri.query).symbolize_keys id_value = parsed_query[:id].first 

note .first, values of query params resolved arrays. additionally, keys parsed in strings, therefore include symbolize_keys convenience , consistency.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -