简体   繁体   English

如何在Rails中修改日期时间哈希?

[英]How do I modify a datetime hash in Rails?

I have a hash like this: 我有一个像这样的哈希:

{"utf8"=>"✓",
 "authenticity_token"=>"yYl/Nts0KRktqjR5K7vYXf1jrOyRJmQOtaF7lPMIeZQ=",
 "meeting"=>{"name"=>"Robsbaun",
 "start_at(3i)"=>"4",
 "start_at(2i)"=>"10",
 "start_at(1i)"=>"2013",
 "start_at(4i)"=>"11",
 "start_at(5i)"=>"15",
 "end_at(1i)"=>"2013",
 "end_at(2i)"=>"10",
 "end_at(3i)"=>"4",
 "end_at(4i)"=>"19",
 "end_at(5i)"=>"15",
 "room_id"=>"1",
 "user_id"=>"2"},
 "commit"=>"Submit"}

And I want to set the same values for both end_at(2i) and start_at(2i) and end_at(3i) and start_at(3i) . 我想为这两个变量的值相同end_at(2i)start_at(2i)end_at(3i)start_at(3i)

How can I do that in Ruby 2.0 and Rails 4? 如何在Ruby 2.0和Rails 4中做到这一点?

I already tried something like: 我已经尝试过类似的东西:

meeting_params[":end_at(3i)"] = meeting_params[":start_at(3i)"]

But it doesn't work. 但这是行不通的。

Thanks in advance. 提前致谢。

Directly changing the value should work, it's just a hash. 直接更改值应该可以,只是一个哈希。 Your syntax isn't quite right though. 但是您的语法不太正确。 Assuming it comes in as params : 假设它以params

params['meeting']['end_at(3i)'] = params['meeting']['start_at(3i)'] 

You're trying to combine symbols and strings - just stick to one or the other. 您正在尝试将符号和字符串组合在一起-只需坚持一个或另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM