I have an app, which is used to plan work shifts for a number of employees. I have a Shift
model, where I store the shiftstart
and the shiftend
as Time
objects.
I present the users Shifts
on a page displaying several days in a table. The idea is that the user the can edit the shiftstart
and shiftend
directly in this table using the Best In Place gem.
But I can't seem to figure out how to get this working when dealing with a Time object - anyone got some experience or suggestions on this.
I have the following code:
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
I'm getting a "undefined method `{:type=>:input}' for "08.00":String" error and I already tried switching the Best In Place Type to something other the input - doesn't help..
best_in_place
method takes two mandatory arguments; an object (shift
in you case) and a field (shiftstart
and shiftend
), then optional hash of options (:type => :input
). So your code needs to be like this:
<%= best_in_place shift, :shiftstart, :type => :input, :display_with => Proc.new { |f| f.strftime("%H.%M") } %>