2

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..

Twiddr
  • 297
  • 1
  • 4
  • 18

1 Answers1

4

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") } %>
Ahmad Sherif
  • 5,923
  • 3
  • 21
  • 27
  • That gives me an error: undefined method `shift_path' for #<#:0x007fe653ce4460>.. any ideas? – Twiddr Dec 22 '12 at 13:56
  • Probably you're not using `ShiftsController` to handle shift's actions. You can supply your actual shift path (the one that handles PUT requests) to `best_in_place` options like this `:path => your_shift_path(shift)`. Or you can supply your `rake routes` for more insights :). – Ahmad Sherif Dec 22 '12 at 14:01
  • Found the problem.. my route was not right.. but your solutions seems to work.. just perfect.. :) – Twiddr Dec 22 '12 at 14:07
  • but do you know how to onlys show the time - ex "08:30" when in edit mode.. right now it displays a date "2000-01-01", the time and the "+100" UTC thingy :) – Twiddr Dec 22 '12 at 14:08
  • This is kinda hack-ish. I don't see BIP have a direct way to do it so I think you have to use JavaScript to change `data-original-content` attribute on the BIP element to the value you want to appear editable. – Ahmad Sherif Dec 22 '12 at 15:07