質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1003閲覧

モーダルが表示されません

RThe

総合スコア25

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/10/15 02:51

モーダルを出すために、レンダリング用のパーシャルやJavaScriptファイルを作成しましたが、
モーダルが表示されません。ターミナルを見たところ、値は取れているように思えます。
お手数ではございますが、解決策を教えて頂けると幸いです。

*verifacation.html.erb(モーダルを出すviewファイル)*

erb

1 2 # モーダルファイルへのリンク 3<p><%= link_to "【お知らせ】", show_overtime_verifacation_user_attendance_path(@user,@overtime), remote: true, class: "notice" %><span class="red_box"><%= "#{@overtime}件"%></span></p> 4 5# モーダルウインドウ表示コード 6<div id= "show-overtime-verifacation" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div>

*_show_overtime_verifacation.html.erb(モーダル用のパーシャル)*

erb

1<div class="modal-dialog modal-lg modal-dialog-center"> 2 <div class="modal-content"> 3 <div class="modal-header"> 4 <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 5 <span aria-hidden="true">&times;</span> 6 </button> 7 </div> 8 9 <div class="modal-body"> 10 <%= form_with(model: @user, url: "#" , method: :patch , local: true) do |f| %> 11 <% @attendances.each do |id, attendance|%> 12 <% user = User.find(id) %> 13 <h3 align="center" class="modal-title"><%= "【#{user.name}からの残業申請】" %></h3> 14 15 <table class="table table-bordered table-condensed overtime_notice-table"> 16 17 <thead class="overtime_notice"> 18 <th>日付</th> 19 <th>曜日</th> 20 <th>終了予定時間</th> 21 <th>指定勤務終了時間</th> 22 <th>時間外時間</th> 23 <th>業務処理内容</th> 24 <th>指示者確認 25 <div class="maru size_small black"> 26 <div class="letter3"></div> 27 </div> 28 </th> 29 <th>変更</th> 30 <th>勤務を確認する</th> 31 </thead> 32 33 <% attendance.each do |day| %> 34 <%= f.fields_for "attendance[]", day do |d| %> 35 36 <tbody class="line"> 37 <% css_class = 38 case $days_of_the_week[day.worked_on.wday] 39 when '土' 40 'text-primary' 41 when '日' 42 'text-danger' 43 end 44 %> 45 <td><%= l(day.worked_on, format: :short) %></td> 46 <td class="<%= css_class %>"><%= $days_of_the_week[day.worked_on.wday] %></td> 47 <td><%= day.overtime_finished_at.try(:strftime,"%H:%M") %></td> 48 <td><%= format_basic_info(user.designation_work_end_time) %></td> 49 <td><%= overtime_worked_on(day.overtime_finished_at, user.designation_work_end_time, day.tomorrow) %></td> 50 <td><%= day.overtime_work %></td> 51 <td><%= d.select :indicater_reply ,{'なし':1, '申請中':2, '承認':3, '否認':4}, { prompt: false}, { class: 'form-control input-sm'} %></td> 52 <td><%= d.check_box :change,id: "change" %></td> 53 <td><%= link_to "確認", verifacation_user_path(user.id), class: "btn btn-primary" %></td> 54 </tbody> 55 56 <% end %> 57 <% end %> 58 </table> 59 <div class="center"> 60 <%= f.submit "変更を送信する", class: "btn btn-primary" %> 61 </div> 62 <% end %> 63 <% end %> 64 </div> 65 </div> 66</div>

*routes.rb*

rb

1Rails.application.routes.draw do 2 3 root 'static_pages#top' 4 5 get '/signup', to: 'users#new' 6 get '/login', to: 'sessions#new' 7 post '/login', to: 'sessions#create' 8 delete '/logout', to: 'sessions#destroy' 9 10 resources :bases 11 resources :users do 12 collection { post :import } 13 member do 14 get 'edit_basic_info' 15 patch 'update_basic_info' 16 patch 'update_index' 17 get 'attendances/edit_one_month' 18 patch 'attendances/update_one_month' 19 # モーダルを出すページ 20 get 'verifacation' 21 end 22 collection do 23 get 'working' 24 end 25 resources :attendances, only: [:update] do 26 member do 27 28 get 'edit_overtime_request' 29 patch 'update_overtime_request' 30 31 get 'edit_overtime_notice' 32 patch 'update_overtime_notice' 33 34 35 # モーダルのルート 36 get 'show_overtime_verifacation' 37 end 38 end 39 end 40 41end 42

*show_overtime_verifacation.js.erb*

erb

1$("#show-overtime-verifacation").html("<%= escape_javascript(render 'show_overtime_verifacation') %>"); 2$("#show-overtime-verifacation").modal("verifacation");

*attendances_controller*

rb

1def show_overtime_verifacation 2 @user = User.find(params[:user_id]) 3 @attendances = Attendance.where(indicater_check_superior: "申請中", indicater_check: @user.name).order(:user_id, :worked_on).group_by(&:user_id) 4 end 5

*モーダルへのリンクボタンを押した際のターミナル*

Started GET "/users/15/attendances/1/show_overtime_verifacation" for 127.0.0.1 at 2020-10-15 11:40:33 +0900 Processing by AttendancesController#show_overtime_verifacation as JS Parameters: {"user_id"=>"15", "id"=>"1"} User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 15], ["LIMIT", 1]] ↳ app/controllers/attendances_controller.rb:70 Attendance Load (1.4ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."indicater_check_superior" = ? AND "attendances"."indicater_check" = ? ORDER BY "attendances"."user_id" ASC, "attendances"."worked_on" ASC [["indicater_check_superior", "申請中"], ["indicater_check", "松井 恵"]] ↳ app/controllers/attendances_controller.rb:72 Rendering attendances/show_overtime_verifacation.js.erb Rendered attendances/_show_overtime_verifacation.html.erb (1.7ms) Rendered attendances/show_overtime_verifacation.js.erb (7.0ms) Completed 200 OK in 44ms (Views: 12.8ms | ActiveRecord: 3.1ms)

*現状はエラーは出ませんが、モーダルも表示されません。
*ひとまず、モーダルが出ればOKです

宜しくお願い申し上げます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問