Публикую здесь ответы на вопрос
как получить данные из params в Ruby on Rails, почерпнутые из интернета.
Мабуть понадобится кому из девелоперов
И неоднократно.
You can access to the select key and over its value to split the content, getting the first one you have "key":
Code:
params = {
"tweet"=>"",
"select"=>"key=qwerty secret=qwerty token=qwerty token_secret=qwerty",
"controller"=>"twitter_postings",
"action"=>"index"
}
p params['select'].split.first
# "key=qwerty"
You can also turn it into a hash if it's easier for you:
Code:
select_hash = params['select'].split.each_with_object(Hash.new(0)) do |element, hash|
key, value = element.split('=')
hash[key] = value
end
p select_hash['key']
# "qwerty
и еще:
Hope this will helping you.
Code:
params = {
"tweet"=>"",
"select"=>"key=qwerty secret=qwerty token=qwerty token_secret=qwerty",
"controller"=>"twitter_postings",
"action"=>"index"
}
for getting key value (qwerty) from this params following query will helping you.
Code:
params["select"].split.first.split("=").second
# => "qwerty"
steps: 1
Code:
params["select"].split
# => ["key=qwerty", "secret=qwerty", "token=qwerty", "token_secret=qwerty"]
find the value and split them
steps: 2
Code:
params["select"].split.first.split("=")
# => ["key", "qwerty"]
pick first value and split again with =
steps: 3
Code:
params["select"].split.first.split("=").second
# => "qwerty"
finally pick the second value.