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

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

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

Yarnは、Facebook/Exponent/Google/Tildeが開発したJavaScriptのパッケージマネージャ。npmよりもインストールが速く、厳密にモジュールのバージョンを固定できるなど、npmの問題を解決。npmと互換性があり、同じpackage.jsonを使用できます。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

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

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

1回答

2344閲覧

rails6 fullcalender5 アプリが表示されない。

a-ichi

総合スコア16

Yarn

Yarnは、Facebook/Exponent/Google/Tildeが開発したJavaScriptのパッケージマネージャ。npmよりもインストールが速く、厳密にモジュールのバージョンを固定できるなど、npmの問題を解決。npmと互換性があり、同じpackage.jsonを使用できます。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 6

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

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2021/01/12 06:40

編集2021/01/12 14:46

前提・実現したいこと

railsアプリで、
以前は問題なく表示されていましたが、
bootstrapの導入を試みたり、DBの名前変更を試みたりしている間に
アプリが全く表示されないようになりました。
ローカル環境も本番環境も同じ状態です。
ページを再読み込みしても改善されません。

もともとの画面表示
イメージ説明

現状
イメージ説明

真っ白になって、何も表示されません。

発生している問題・エラーメッセージ

検証ツール

preact.module.js:341 Uncaught TypeError: Cannot read property '__k' of null at O (preact.module.js:341) at DelayedRunner.Calendar._this.handleRenderRequest [as drainedOption] (main.js:48) at DelayedRunner.drained (main.js:8619) at DelayedRunner.tryDrain (main.js:8597) at DelayedRunner.request (main.js:8546) at Calendar.render (main.js:105) at HTMLDocument.<anonymous> (calender.js:55) at Object../node_modules/turbolinks/dist/turbolinks.js.e.dispatch (turbolinks.js:75) at r.notifyApplicationAfterPageLoad (turbolinks.js:994) at r.pageLoaded (turbolinks.js:948)

該当のソースコード

index.json.jbuilder

json

1json.array!(@events) do |event| 2 json.extract! event, :id, :title, :body 3 json.start event.start_time 4 json.end event.end_time 5 json.url event_url(event, format: :html) 6end

calender.js

js

1import { Calendar } from '@fullcalendar/core'; 2import dayGridPlugin from '@fullcalendar/daygrid'; 3import interactionPlugin from '@fullcalendar/interaction'; 4import listPlugin from '@fullcalendar/list'; 5import timeGridPlugin from '@fullcalendar/timegrid'; 6 7document.addEventListener('turbolinks:load', function() { 8 9 let calendarEl = document.getElementById('calendar'); 10 let calendar = new Calendar(calendarEl, { 11 navLinks: true, 12 editable: true, 13 nowIndicator: true, 14 initialView: 'dayGridMonth', 15 displayEventTime: false, 16 17 locale: 'ja', 18 timeZone: 'Asia/Tokyo', 19 height: 600, 20 headerToolbar: { 21 left: "dayGridMonth,timeGridWeek,timeGridDay,listMonth", 22 center: "title", 23 right: "today prev,next" 24 }, 25 buttonText: { 26 today: '今日', 27 month: '月', 28 list: 'リスト', 29 week: '週', 30 day: '日', 31 }, 32 views: { 33 timeGridWeek: { 34 slotMinTime: '07:00:00', 35 slotMaxTime: '22:00:00' 36 }, 37 timeGridDay: { 38 slotMinTime: '07:00:00', 39 slotMaxTime: '22:00:00' 40 } 41 }, 42 eventClick: function(event) { 43 }, 44 dayCellContent: function(e) { 45 e.dayNumberText = e.dayNumberText.replace('日', ''); 46 }, 47 48 eventSources: [{url:'/events.json', 49 color: '#2ECCFA'} 50 ], 51 plugins: [ dayGridPlugin, timeGridPlugin, interactionPlugin, listPlugin, ] 52 }); 53 54 55 calendar.render(); 56}); 57

applicarion.js

js

1require("@rails/ujs").start() 2require("turbolinks").start() 3require("@rails/activestorage").start() 4require("channels") 5require("../calender.js") 6require('jquery') 7

event_controller.rb

ruby

1class EventsController < ApplicationController 2 before_action :set_event, only: [:show, :edit, :update, :destroy] 3 before_action :move_to_index,except:[:index] 4 5 6 7 def index 8 @events = Event.all 9 @customer = Customer.all 10 end 11 12 def new 13 @event = Event.new 14 end 15 16 def create 17 @event = Event.create(event_params) 18 19 if @event.save 20 redirect_to root_path, notice: "イベントを登録しました" 21 else 22 redirect_to new_event_path, notice: "登録出来ませんでした" 23 end 24 end 25 26 def destroy 27 if @event.destroy 28 redirect_to root_path, notice: 'イベントを削除しました' 29 else 30 flash.now[:alert] = 'イベントを削除できませんでした' 31 render :show 32 end 33 end 34 35 def edit 36 end 37 38 def update 39 if @event.update(event_params) 40 redirect_to root_path, notice: 'イベントを編集しました' 41 else 42 flash.now[:alert] = '必須事項を入力してください' 43 render :edit 44 end 45 end 46 47 def show 48 end 49 50 51 52 private 53 54 def set_event 55 @event = Event.find(params[:id]) 56 end 57 58 def event_params 59 params.require(:event).permit(:title, :body, :start_time, :end_time, :user, customer_ids:[]).merge(user_id: current_user.id) 60 end 61 62 def move_to_index 63 unless user_signed_in? 64 redirect_to action: :index 65 end 66 end 67 68end 69

webpacker.yml

yml

1# Note: You must restart bin/webpack-dev-server for changes to take effect 2 3default: &default 4 source_path: app/javascript 5 source_entry_path: packs 6 public_root_path: public 7 public_output_path: packs 8 cache_path: tmp/cache/webpacker 9 check_yarn_integrity: false 10 webpack_compile_output: true 11 12 # Additional paths webpack should lookup modules 13 # ['app/assets', 'engine/foo/app/assets'] 14 resolved_paths: [] 15 16 # Reload manifest.json on all requests so we reload latest compiled packs 17 cache_manifest: false 18 19 # Extract and emit a css file 20 extract_css: false 21 22 static_assets_extensions: 23 - .jpg 24 - .jpeg 25 - .png 26 - .gif 27 - .tiff 28 - .ico 29 - .svg 30 - .eot 31 - .otf 32 - .ttf 33 - .woff 34 - .woff2 35 36 extensions: 37 - .mjs 38 - .js 39 - .sass 40 - .scss 41 - .css 42 - .module.sass 43 - .module.scss 44 - .module.css 45 - .png 46 - .svg 47 - .gif 48 - .jpeg 49 - .jpg 50 51development: 52 <<: *default 53 compile: true 54 55 # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules 56 check_yarn_integrity: true 57 58 # Reference: https://webpack.js.org/configuration/dev-server/ 59 dev_server: 60 https: true 61 host: localhost 62 port: 3035 63 public: localhost:3035 64 hmr: false 65 # Inline should be set to true if using HMR 66 inline: true 67 overlay: true 68 compress: true 69 disable_host_check: true 70 use_local_ip: false 71 quiet: false 72 pretty: false 73 headers: 74 'Access-Control-Allow-Origin': '*' 75 watch_options: 76 ignored: '**/node_modules/**' 77 78 79test: 80 <<: *default 81 compile: true 82 83 # Compile test packs to a separate directory 84 public_output_path: packs-test 85 86production: 87 <<: *default 88 89 # Production depends on precompilation of packs prior to booting for performance. 90 compile: true 91 92 # Extract and emit a css file 93 extract_css: false 94 95 # Cache manifest.json for performance 96 cache_manifest: true 97

development.js

js

1process.env.NODE_ENV = process.env.NODE_ENV || 'development' 2 3const environment = require('./environment') 4 5module.exports = environment.toWebpackConfig() 6

enviroment.js

js

1const { environment } = require('@rails/webpacker') 2 3const webpack = require('webpack') 4environment.plugins.prepend( 5 'Provide', 6 new webpack.ProvidePlugin({ 7 $: 'jquery', 8 jQuery: 'jquery', 9 Popper: 'popper.js' 10 }) 11) 12module.exports = environment 13

index.html.haml

haml

1.Customer-contents 2 -if user_signed_in? 3 .Side 4 .Side__header 5 顧客一覧 6 .Side__body 7 .Side__body__customer 8 -@customer.each do |customer| 9 -if user_signed_in? 10 -if current_user.id == customer.user_id 11 .Customer-name 12 =link_to customer_path(customer.id),class: "Customer-name__btn" do 13 =customer.name 14 .Side__footer 15 =link_to(new_customer_path,class: "Side-btn") do 1617 顧客登録 18 .Main 19 .Main__header 20 .Main__header__contents 21 .Main__header__contents__left 22 CustomerCalender 23 .Main__header__contents__right 24 -if user_signed_in? 25 =link_to(destroy_user_session_path,method: :delete,class: "Right__login") do 26 ログアウト 27 - else 28 = link_to(users_guest_sign_in_path, method: :post,class: "Right__login" ) do 29 ゲストログイン(閲覧用) 30 =link_to(new_user_session_path,class: "Right__login") do 31 ログイン 32 =link_to(new_user_registration_path,class: "Right__new") do 33 新規登録 34 .Main__body 35 -if user_signed_in? 36 %p#calendar 37 .Main__footer 38 .Main__footer__content 39 -if user_signed_in? 40 =link_to(new_event_path,class: "Footer-btn") do 4142 スケジュール入力 43 44 45 46 -if user_signed_in? 47 .Side-hiden 48 .Side-hiden__header 49 顧客一覧 50 .Side-hiden__body 51 .Side-hiden__body__customer 52 -@customer.each do |customer| 53 -if user_signed_in? 54 -if current_user.id == customer.user_id 55 .Customer-name 56 =link_to customer_path(customer.id),class: "Customer-name__btn" do 57 =customer.name 58 .Side-hiden__footer 59 =link_to(new_customer_path,class: "Side-btn") do 6061 顧客登録

試したこと

・yarn install
・mysql.server start
・yarn add fullcalendar
・rails webpacker:install
・bin/webpack
・xcode-select --install
・npm install @fullcalendar/core @fullcalendar/daygrid @fullcalendar/timegrid @fullcalendar/list @fullcalendar/Interaction

補足情報(FW/ツールのバージョンなど)

ruby '2.6.5'
rails '6.0.0'
fullcalender v5
gem 'mysql2', '>= 0.4.4'
gem 'webpacker', '> 4.0'
gem 'turbolinks', '
> 5'
gem "devise"
webpack-dev-server@3.11.1


yarnとかwebpack系のエラーかと思い、
調べて再installなどしてみましたが、改善されませんでした。
皆様のお力をお借り出来ればと思います。

何卒よろしくお願い致します。

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

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

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

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

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

Mugheart

2021/01/12 06:57

えーと、何がわからないのでしょうか?エラーメッセージに書いてある通りなので、まずはそのエラーを解決するところがネクストアクションになると思うのですが、エラーメッセージが読めない(英語が読めない)ということでしょうか? ActionView::Template::Error (undefined method `id' for nil:NilClass) エラーメッセージというのはこれのことです。
a-ichi

2021/01/12 07:43 編集

Mugheart様 コメントありがとうございます。 deviseのログアウト時のpathを記載しましたら一回解決したように見えましたが、解決出来てませんでした。 エラーメッセージがそれだとは認識出来たのですが、解決方法が分かりませんでした。 以前までは、このようなエラーが出た事がなく、通常に遷移出来ていたので、jsonファイルに問題があるとは思えず、bootstrapの導入を試みたり、ローカルdbの名前の変更を試みたりした後で、このようなエラーになった為、 yarnとかwebpack系の問題だと思っていました。 上記のエラーは、idが無い為、トップページを表示出来ないというエラーという事でしょうか?
Mugheart

2021/01/13 02:07

undefined method `id' for nil:NilClass Google翻訳にかけると nil:NilClassの未定義のメソッド `id ' となります。もう少し綺麗にすると NilClassのnilというオブジェクトに対してidというメソッドは定義されていません となります。すなわち nil.id が実行されているということです。 idメソッドを実行しているところを探してみると current_user.id というのがあります(今は質問内容から消えているようですが)、このcurrent_userがnilになっているということですね。
a-ichi

2021/01/13 02:17

Mugheart様 なるほど、理解出来ました。 丁寧にご説明頂きまして、ありがとうございます。 その部分は削除してみたのですが、エラーは解消されなかったので、 他にも原因があるみたいです。
guest

回答1

0

自己解決

トップページを未ログインの場合、
ログインページに遷移するように変更した事で解決しました。

投稿2021/01/12 07:09

編集2021/01/13 04:46
a-ichi

総合スコア16

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問