1日単位の単発予約と月単位のまとめて予約ができる機能を作成中です。
後者のページでは今月のテーブルが表示され、単発予約日がある場合は、予約日に内容が表示される仕様にしたいのですが、
予約していない日のテーブルが表示されない状況です。
かれこれ数日詰まっていますので、
お忙しい中大変お手数おかけしますが、解決策を教えていただけると幸いです。
rb
1*reception_controller(該当部分) 2 3def month_edit 4 @first_day = Date.current.beginning_of_month 5 @last_day = @first_day.end_of_month 6 one_month = [*@first_day..@last_day] 7 @receptions = current_user.receptions.where(date_of_use: one_month) 8 unless one_month.count == current_user.receptions.count 9 ActiveRecord::Base.transaction do 10 one_month.each { |day| current_user.receptions.where(date_of_use: day) } 11 end 12 @receptions = current_user.receptions.where(date_of_use: one_month) 13 end 14 15rescue ActiveRecord::RecordInvalid 16 flash[:danger] = "ページ情報の取得に失敗しました、再アクセスしてください。" 17 redirect_to root_url 18end 19 20 21private 22 23 def reception_params 24 params.require(:reception).permit(:request,:date_of_use,:date_of_use, :start_time, :end_time, :start_transfer, :end_transfer, :start_place, :end_place, :event, :remarks).merge(user_id: current_user.id) 25 end 26 27
erb
1 2*1ヶ月単位の予約ページ* 3 4<div class="js-message-errors"></div> 5 <h1><%= current_user.name %>様</h1> 6 <%= form_with(model: @user, url: month_update_users_reception_path(day: @first_day), local: true) do |f| %> 7 <table class="table table-bordered"> 8 <thead> 9 <tr> 10 <th>受付済</th> 11 <th>ご利用日</th> 12 <th style="width: 50px">曜日</th> 13 <th>迎え時間</th> 14 <th>迎え場所</th> 15 <th style="width: 100px"> 迎え有無</th> 16 <th>送り時間</th> 17 <th>送り場所</th> 18 <th style="width: 100px"> 送り有無</th> 19 <th style="width: 100px">イベント</th> 20 <th>備考</th> 21 </tr> 22 </thead> 23 <tbody> 24 <% @receptions.each do |day| %> 25 <%= f.fields_for "receptions[]", day do |r| %> 26 <% css_class = 27 case $days_of_the_week[day.date_of_use.wday] 28 when '土' 29 'text-primary' 30 when '日' 31 'text-danger' 32 end 33 %> 34 <tr> 35 <td><%= r.check_box :request %></td> 36 <td><%= l(day.date_of_use, format: :short) %></td> 37 <td class="<%= css_class %>"><%= $days_of_the_week[day.date_of_use.wday] %></td> 38 <td><%= r.time_field :start_time,{ max: "18:30", min: "08:30", class: "form-control input-sm" }%></td> 39 <td><%= r.select :start_place, [ ["自宅",1], ["学校 or 園", 2], ["祖父母宅", 3 ] ,["なし", 4]], {prompt: "迎え場所を選択"}, {class: "form-control input-sm" } %></td> 40 <td><%= r.check_box :start_transfer,{checked: true}, "true", "false" %></td> 41 <td><%= r.time_field :end_time,{ max: "18:30", min: "08:30", class: "form-control input-sm" } %></td> 42 <td><%= r.select :end_place, [ ["自宅",1], ["祖母宅", 2], ["その他", 3 ] ,["なし", 4]], {prompt: "送り場所を選択"}, {class: "form-control input-sm" } %></td> 43 <td><%= r.check_box :end_transfer,{checked: true}, "true", "false" %></td> 44 <td><%= r.check_box :event,{checked: false}, "true", "false" %></td> 45 <td><%= r.text_field :remarks, class: "form-control" %></td> 46 </tr> 47 <% end %> 48 <% end %> 49 </tbody> 50 </table> 51 <div class="table_modal"> 52 <%= link_to "キャンセル", user_path(current_user), class: "btn btn-primary" %> 53 <%= f.submit "編集を保存する", class: "btn btn-primary" %> 54 </div> 55 <% end %> 56 57
rb
1 2*reception(予約)テーブルのマイグレーション* 3 4class CreateReceptions < ActiveRecord::Migration[5.2] 5 def change 6 create_table :receptions do |t| 7 t.references :admin, foreign_key:true 8 t.references :user, foreign_key:true 9 t.boolean :request 10 t.date :date_of_use 11 t.time :start_time 12 t.time :end_time 13 t.boolean :start_transfer 14 t.boolean :end_transfer 15 t.string :start_place 16 t.string :end_place 17 t.boolean :event 18 t.string :remarks 19 20 t.timestamps 21 22 end 23 end 24end 25
erb
1 2*user_show.html.erb* 3 4<h1><%= @user.name %> 様</h1> 5<div class="col-md-5 col-md-offset-7" > 6 <%= link_to "受付追加(日単位)",new_users_reception_path, class: "btn btn-default", remote: true %> 7 <%= link_to "受付追加(月単位)", month_edit_users_reception_path(date: @first_day), class: "btn btn-default", local: true %> 8⬆️ こちらから、1ヶ月の登録ページに遷移します。 9</div> 10<div class="col-md-10 col-md-offset-1" id="table-users"> 11 <%= month_calendar events: @reception do |date,reception | %> 12 <% if Date.current <= date %> 13 <%= link_to date.day, users_reception_path(date), remote: true %> 14 <% else %> 15 <%= link_to date.day, "#", class: "disabled" %> 16 <% end %> 17 <% end %> 18</div> 19 20<div id="new" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div> 21<div id="show" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div> 22<div id="show-new" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div>
1ヶ月ページに遷移した際のターミナル Started GET "/users/receptions/2/month_edit" for 127.0.0.1 at 2021-02-24 14:59:49 +0900 Processing by Users::ReceptionsController#month_edit as HTML Parameters: {"id"=>"2"} User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]] ↳ app/controllers/users/receptions_controller.rb:38 (0.2ms) SELECT COUNT(*) FROM "receptions" WHERE "receptions"."user_id" = ? [["user_id", 2]] ↳ app/controllers/users/receptions_controller.rb:39 (0.1ms) begin transaction ↳ app/controllers/users/receptions_controller.rb:40 (0.1ms) commit transaction ↳ app/controllers/users/receptions_controller.rb:40 Rendering users/receptions/month_edit.html.erb within layouts/application Reception Load (0.6ms) SELECT "receptions".* FROM "receptions" WHERE "receptions"."user_id" = ? AND "receptions"."date_of_use" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["user_id", 2], ["date_of_use", "2021-02-01"], ["date_of_use", "2021-02-02"], ["date_of_use", "2021-02-03"], ["date_of_use", "2021-02-04"], ["date_of_use", "2021-02-05"], ["date_of_use", "2021-02-06"], ["date_of_use", "2021-02-07"], ["date_of_use", "2021-02-08"], ["date_of_use", "2021-02-09"], ["date_of_use", "2021-02-10"], ["date_of_use", "2021-02-11"], ["date_of_use", "2021-02-12"], ["date_of_use", "2021-02-13"], ["date_of_use", "2021-02-14"], ["date_of_use", "2021-02-15"], ["date_of_use", "2021-02-16"], ["date_of_use", "2021-02-17"], ["date_of_use", "2021-02-18"], ["date_of_use", "2021-02-19"], ["date_of_use", "2021-02-20"], ["date_of_use", "2021-02-21"], ["date_of_use", "2021-02-22"], ["date_of_use", "2021-02-23"], ["date_of_use", "2021-02-24"], ["date_of_use", "2021-02-25"], ["date_of_use", "2021-02-26"], ["date_of_use", "2021-02-27"], ["date_of_use", "2021-02-28"]] ↳ app/views/users/receptions/month_edit.html.erb:23 Rendered users/receptions/month_edit.html.erb within layouts/application (13.0ms) Rendered layouts/_header.html.erb (1.2ms) Rendered layouts/_flashes.html.erb (0.5ms) Completed 200 OK in 75ms (Views: 64.7ms | ActiveRecord: 1.1ms)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/02/25 09:06
2021/02/25 10:57
2021/02/26 02:42