前提・実現したいこと
勤怠表のウェブアプリを作成しています。
出社と退社の打刻時間編集画面にてdatetime_selectにより任意の時間を選択して更新するという機能を実装したいのですが、パラメータの受け取り方でわからない部分があったのでご存知の方いらっしゃいましたらよろしければ教えてください。
発生している問題
更新ボタンを押した後にリダイレクトをし任意のページに戻ることはできるのですが、 表示時間は編集前の元の時間から更新されていない状態です。
該当のソースコード
rails 5.1.6
[DB]
出社時間: at_in
退社時間: at_out
lang
1<div> 2 <%= form_for(@punch) do |f| %> 3 <%= render 'shared/error_messages', object: f.object %> 4 5 <%= f.label :at_in, "出社時間" %> 6 <%= f.datetime_select :at_in, minute_step: 5 %> 7 8 <%= f.label :at_out, "退社時間" %> 9 <%= f.datetime_select :at_out, minute_step: 5, include_blank: true %> 10 <% end %> 11 <%= f.submit "更新", class: "btn btn-primary" %> 12 <% end %> 13</div>
更新ボタンを押してdatetime_selectで渡されたパラメータ
lang
1"punch" => { 2 "at_in(1i)" => "2018", 3 "at_in(2i)" => "10", 4 "at_in(3i)" => "15", 5 "at_in(4i)" => "10", 6 "at_in(5i)" => "00", 7 "at_out(1i)" => "2018" 8 "at_out(2i)" => "10" 9 "at_out(3i)" => "15" 10 "at_out(4i)" => "19" 11 "at_out(5i)" => "30" 12}
対応controller
lang
1 def edit 2 @punch = Punch.find_by(params[:id]) 3 end 4 5 def update 6 @punch = Punch.find_by(params[:id]) 7 @punch.at_in = (params[:punch][:at_in]) 8 @punch.at_out = (params[:punch][:at_out]) 9 if @punch.save 10 flash[:success] = "打刻時間を更新しました" 11 redirect_to '/punches' 12 else 13 render 'edit' 14 end 15 end
datetime_selectフォームののパラメータをat_inとat_outで区別して受け取る方法がどうやらうまくいっていないのかと思うのですが方法が見つからない状態です。
解決方法有りましたらよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/12/06 13:00