2012-12-22 53 views
2

我有一个应用程序,用于为多个员工计划工作班次。我有一个Shift模型,在那里我存储shiftstartshiftend作为Time对象。对时间对象进行编辑

我在一个表格中显示几天的页面上显示用户Shifts。这个想法是,用户可以使用Best In Place宝石直接在该表中编辑shiftstartshiftend

但是我似乎无法弄清楚如何在处理Time对象时得到这个工作 - 任何人都可以在这方面获得一些经验或建议。

我有以下代码:

VIEW:

<% @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 %> 

SCHEMA:

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 

我得到一个“未定义的方法`{:类型=>:输入} '为“08.00”:字符串“错误,我已经尝试切换到最好的地方类型输入的东西 - 没有帮助..

回答

4

best_in_place方法需要两个强制参数;一个对象(在你的情况下为shift)和一个字段(shiftstartshiftend),然后是可选的选项散列(:type => :input)。所以,你的代码需要是这样的:

<%= best_in_place shift, :shiftstart, :type => :input, :display_with => Proc.new { |f| f.strftime("%H.%M") } %> 
+0

这给了我一个错误:未定义的方法'shift_path”为#<#<类别:0x007fe659934800>:0x007fe653ce4460> ..任何想法? – Twiddr

+0

也许你没有使用'ShiftsController'来处理轮班的动作。您可以将您的实际移位路径(处理PUT请求的路径)提供给''best_in_place''选项,如下所示::path => your_shift_path(shift)'。或者你可以提供你的'rake routes'以获得更多的见解:)。 –

+0

发现问题..我的路线不正确..但你的解决方案似乎工作..只是完美.. :) – Twiddr