如何从params获得“关键”?

时间:2022-03-13 18:31:42
<%= params[:select] %>  # key=qwerty secret=qwerty token=qwerty token_secret=qwerty

Please tell me how I can get "key" ? I do not understand:

请告诉我如何获得“钥匙”?我不明白:

<%= params{[:select[:key]]} %> # {"tweet"=>"", "select"=>"key=qwerty secret=qwerty token=qwerty token_secret=qwerty", "controller"=>"twitter_postings", "action"=>"index"}

2 个解决方案

#1


1  

You can access to the select key and over its value to split the content, getting the first one you have "key":

您可以访问select键及其值以拆分内容,获得第一个“key”:

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:

如果您更容易,也可以将其变为哈希:

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

#2


0  

Hope this will helping you.

希望这会对你有所帮助。

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.

从这个参数获取键值(qwerty)后面的查询将帮助你。

params["select"].split.first.split("=").second
# => "qwerty"

steps: 1

步骤:1

params["select"].split
# => ["key=qwerty", "secret=qwerty", "token=qwerty", "token_secret=qwerty"]

find the value and split them

找到值并拆分它们

steps: 2

步骤:2

params["select"].split.first.split("=")
# => ["key", "qwerty"]

pick first value and split again with =

选择第一个值并再次使用=拆分

steps: 3

步骤:3

params["select"].split.first.split("=").second
# => "qwerty"

finally pick the second value.

最后选择第二个值。

#1


1  

You can access to the select key and over its value to split the content, getting the first one you have "key":

您可以访问select键及其值以拆分内容,获得第一个“key”:

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:

如果您更容易,也可以将其变为哈希:

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

#2


0  

Hope this will helping you.

希望这会对你有所帮助。

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.

从这个参数获取键值(qwerty)后面的查询将帮助你。

params["select"].split.first.split("=").second
# => "qwerty"

steps: 1

步骤:1

params["select"].split
# => ["key=qwerty", "secret=qwerty", "token=qwerty", "token_secret=qwerty"]

find the value and split them

找到值并拆分它们

steps: 2

步骤:2

params["select"].split.first.split("=")
# => ["key", "qwerty"]

pick first value and split again with =

选择第一个值并再次使用=拆分

steps: 3

步骤:3

params["select"].split.first.split("=").second
# => "qwerty"

finally pick the second value.

最后选择第二个值。