こんにちは。
Ruby on Railsを使ってWebアプリケーションを開発しています。
開発中、railsサーバーを立ち上げようとしたらmapping values are not allowed in this context
という内容のエラーに遭遇しました。
今回はmapping values are not allowed in this context
でrailsサーバーが立ち上がらない問題の解決方法をご紹介していきます。
mapping values are not allowed in this contextでサーバーが起動しない!
症状としてはターミナルからrails s コマンドを実行時、以下のようなエラーメッセージが表示されました。
# rails s
=> Booting Puma
=> Rails 5.1.6.1 application starting in development
=> Run `rails server -h` for more startup options
Exiting
/usr/local/lib/ruby/2.4.0/psych.rb:377:in `parse': (<unknown>): mapping values are not allowed in this context at line 240 column 10 (Psych::SyntaxError)
(<unknown>): mapping values are not allowed in this context at line 240 column 10 (Psych::SyntaxError)
240行目のマッピング値が許可されない?みたいなことを仰っているようです。
Psych::SyntaxError
というメッセージから察するに、構文エラー系な気がしますね。
mapping values are not allowed in this contextでサーバーが起動しない! 解決方法
.ymlファイルを確認する!
mapping values are not allowed in this context
で似たような症状の人がいないか調査してみました。
すると上記の症状は、サーバー起動時に読み込むdatabase.ymlなどのymlファイルに構文エラーがあると発生する症状みたいでした。
今回はRails製の顧客管理Gem『FatFreeCRM』を利用していたのですが、こちらのsetting.default.ymlという設定ファイルに記述ミスがあったことが原因だったようです。
setting.default.ymlを修正して再びサーバーを再起動すると…
root@123e151e45b0:~# rails s
=> Booting Puma
=> Rails 5.1.6.1 application starting in development
=> Run `rails server -h` for more startup options
[640] Puma starting in cluster mode...
mapping values are not allowed in this context
のエラーメッセージが解消され、無事にサーバーが立ち上がりました!やった!
mapping values are not allowed in this contextでサーバーが起動しない! まとめ
![ruby-on-rails](https://tanarizm.com/wp-content/uploads/2019/07/ruby-on-rails.jpg)
ということで今回はmapping values are not allowed in this contextでサーバーが起動できない問題の解消方法についてご紹介いたしました。
最近なにかと多いrailsエラー解消シリーズ。
今回のエラーについては、終わってみればタイポでエラー起こした結果エラー吐かれて、訳も分からずドタバタと調査してしまった感じになっちゃいましたね。恥ずかしい。
恥ずかしさもブログにしたためることで自らの戒めに……なるといいなあ。
短いですが、今回はここまで。