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
Post a Comment