Ruby on rails RubyonRails-从params生成时间
我有以下参数:Ruby on rails RubyonRails-从params生成时间,ruby-on-rails,time,parameters,Ruby On Rails,Time,Parameters,我有以下参数: {"utf8"=>"✓", "authenticity_token"=>"sPoWmnLU984Py9BEIe8MgEVo8tqPsSdLznFZ0dITXAw=", "event"=>{"title"=>"", "description"=>"", "day"=>"2013-11-21", "start(1i)"=>"2013", "start(2i)"=>"11", "start(3i)"=>"25",
{"utf8"=>"✓",
"authenticity_token"=>"sPoWmnLU984Py9BEIe8MgEVo8tqPsSdLznFZ0dITXAw=",
"event"=>{"title"=>"",
"description"=>"",
"day"=>"2013-11-21",
"start(1i)"=>"2013",
"start(2i)"=>"11",
"start(3i)"=>"25",
"start(4i)"=>"07",
"start(5i)"=>"00",
"end(1i)"=>"2013",
"end(2i)"=>"11",
"end(3i)"=>"25",
"end(4i)"=>"07",
"end(5i)"=>"00",
"day_id"=>"day"},
"commit"=>"Event erstellen"}
和我的控制器:
start = "#{params[:event][:start(4i)]}:#{params[:event][:start(5i)]}"
我只需要参数中的times属性,因此在最后我有如下内容:
07:00
如果“start”是模型的DateTime属性,则可以简单地使用DateTime的strftime方法。类似start.strftime(“%H:%M”)那么,您的问题是什么?你想用你拥有的数据创建一个时间实例吗?我只需要参数中的times属性,这样在最后我就有了这样的东西:07:00你的模型中是否有一个
start
和end
属性(可能是虚拟的)(根据你的参数假设)?看起来“start”是模型的一个DateTime属性。您可以简单地使用DateTime的strftime方法来实现此strftime(“%H:%M”)