2

多くの従業員の勤務シフトを計画するために使用されるアプリがあります。とをオブジェクトとしてShift保存するモデルがあります。shiftstartshiftendTime

Shifts表に数日を表示するページにユーザーを表示します。アイデアは、ユーザーがBest In Place gemを使用して、このテーブルshiftstartshiftend直接編集できるということです。

しかし、 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 を入力以外のものに切り替えようとしましたが、役に立ちません..

4

1 に答える 1

4

best_in_placeメソッドは 2 つの必須引数を取ります。オブジェクト(shiftあなたの場合)とフィールド(shiftstartおよびshiftend)、オプションのオプションのハッシュ(:type => :input)。したがって、コードは次のようにする必要があります。

<%= best_in_place shift, :shiftstart, :type => :input, :display_with => Proc.new { |f| f.strftime("%H.%M") } %>
于 2012-12-22T13:30:57.990 に答える