我有一个应用程序,用于为多个员工计划轮类。我有一个 Shift
模型,其中将 shiftstart
和 shiftend
存储为 Time
对象。
我在一个页面上显示用户类次
,并在表格中显示几天。这个想法是,用户可以使用 Best In Place 直接在此表中编辑 shiftstart
和 shiftend
gem 。
但我似乎无法弄清楚在处理 Time 对象时如何使其工作 - 任何人都对此有一些经验或建议。
我有以下代码:
查看:
<% @myShifts.where(:shiftdate => date).order(:shiftstart).each do |shift| %>
<div class="shift-item span">
<div class="hider">
<p>
<i class="icon gear"></i>
<%= best_in_place shift.shiftstart.strftime("%H.%M"), :type => :input %> - <%= best_in_place shift.shiftend.strftime("%H.%M"), :type => :input %>
</p>
</div>
</div>
<% end %>
架构:
create_table "shifts", :force => true do |t|
t.time "shiftstart"
t.time "shiftend"
t.integer "type_id"
t.integer "user_id"
t.string "note"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.date "shiftdate"
end
我收到“undefined method `{:type=>:input}' for "08.00":String”错误,并且我已经尝试将 Best In Place Type 切换为其他类型输入 - 没有帮助..
最佳答案
best_in_place
方法采用两个强制参数;一个对象(shift
在你的情况下)和一个字段(shiftstart
和 shiftend
),然后是可选的选项哈希(:type = > :输入
)。所以你的代码需要像这样:
<%= best_in_place shift, :shiftstart, :type => :input, :display_with => Proc.new { |f| f.strftime("%H.%M") } %>
关于ruby-on-rails - 就地编辑时间对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14002890/