rails gしたら`method_missing': undefined method `load_defaults' ってエラー出た
Gemfile
source 'https://rubygems.org' gem 'rails', '5.0.3' gem 'puma', '3.9.1' gem 'bootstrap-sass', '3.3.6' gem 'sass-rails', '5.0.6' gem 'uglifier', '3.2.0' gem 'coffee-rails', '4.2.2' gem 'jquery-rails', '4.3.1' gem 'turbolinks', '5.0.1' gem 'jbuilder', '2.6.1' gem 'therubyracer' group :development, :test do gem 'sqlite3', '1.3.13' gem 'byebug', '9.0.6', platform: :mri end group :development do gem 'web-console', '3.5.1' gem 'listen', '3.0.8' end group :test do gem 'rails-controller-testing', '1.0.2' gem 'minitest-reporters', '1.1.14' end group :production do gem 'pg', '0.18.4' end
CentOS環境にはRails 5.1〜, GemfileにはRails 5.0〜を指定してbundle update, bundle installした。
その結果rails gした際に以下のエラー発生。
# webyaji=筆者の開発アプリ [vagrant@localhost webyaji]$ rails g model test /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x007fa562795108> (NoMethodError) from /home/vagrant/app/webyaji/config/application.rb:12:in `<class:Application>' from /home/vagrant/app/webyaji/config/application.rb:10:in `<module:Webyaji>' from /home/vagrant/app/webyaji/config/application.rb:9:in `<top (required)>' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:156:in `require' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:156:in `require_application_and_environment!' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:143:in `generate_or_destroy' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:60:in `generate' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!' from /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>' from bin/rails:9:in `require' from bin/rails:9:in `<main>'
たぶんload_defaultsとかいうメソッドしらねーよって怒られてる。
一時間ほどハマったが調べていくとload_defaultsがRails5.1系から使えるようになったメソッドと判明。
# config/application.rb require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Webyaji class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.1 + # config.load_defaults 5.1 # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. end end
コメントアウト後、再度rails gして大丈夫になったことを確認。
[vagrant@localhost webyaji]$ rails g model test Expected string default value for '--jbuilder'; got true (boolean) invoke active_record create db/migrate/20170725131230_create_tests.rb create app/models/test.rb invoke test_unit create test/models/test_test.rb create test/fixtures/tests.yml
Vagrantで立ち上げた仮想CentOSのファイルをCyberduckから操作したい
環境
OSX EICapitan
Vagrant 1.9.7
VirtualBox 5.1.24
CentOS7
下準備
さくらVPS(CentOS7)をWebサーバ化してHelloWorldする
環境
さくらのVPS CentOS7
ログイン
$ ssh root@[IPアドレス]
パスワード入力欄が出てくるので入力してrootで入る。
Apacheを入れる
# yum -y install httpd # systemctl start httpd.service # systemctl enable httpd.service
起動と自動起動設定もしておく。
ファイアウォール設定
ポート開放コマンド。
# firewall-cmd --zone=public --add-service=http --permanent # firewall-cmd --add-port=80/tcp --zone=public --permanent # firewall-cmd --reload
これでブラウザで見に行った際に拒否されない。
htmlファイル作成
# vi /var/www/html/index.html
< !-- /var/www/html/index.html -- >
Hello World
表示確認
ブラウザのアドレスバーにVPSのIPアドレスを打ち込みENTER。
Hello World表示が見えたら成功。
VagrantでCentOS7立ち上げてみる
筆者環境
OSX EICapitan
VirtualBoxをインストール
Vagrant by HashiCorp
ここから。
pkg開くときに検証中と出て進まないときは以下のコマンドで対応。
$ sudo installer -package /Volumes/VirtualBox/VirtualBox.pkg -target /
Vagrantインストール
Vagrant by HashiCorp
ここから。
同上の現象で進めなくなった場合は以下コマンド。
$ sudo installer -package /Volumes/Vagrant/Vagrant.pkg -target /
Box追加
Discover Vagrant Boxes - Vagrant Cloud
ここから好きな環境を選んで落としてくればいいっぽい(自己責任)。
CentOS7が欲しいのでこれをチョイス。
$ vagrant box add centos/7
エラー起きたら以下参照。
vagrant 1.8.7 でboxを追加しようとするとエラーになる時の対処法 - Qiita
ボックスはあくまでテンプレート。鋳型のようなもん(たぶん)。
続いてボックスを実体として立ち上げていく。
CentOS7 mysqlがインストールできない
$ sudo yum install mysql-server 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.riken.jp * extras: ftp.iij.ad.jp * updates: centosk3.centos.org パッケージ mysql-server は利用できません。 エラー: 何もしません
エラーの原因は正確にはわからないが、デフォルトで入ってるmariaDBと競合する場合があるという記事を発見。
下記の通りに実施したら無事インストールできた。
$ sudo yum remove mariadb-libs $ sudo rm -rf /var/lib/mysql/ $ sudo yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm $ sudo yum -y install mysql-community-server $ mysqld --version mysqld Ver 5.7.19 for Linux on x86_64 (MySQL Community Server (GPL))
ドットインストールの「さくらのVPS入門」の手順通りに進めたらハマったのでメモ
CentOSのcronで定期作業を自動で行わせる
環境
さくらのVPS CentOS6
動機
railsアプリケーションを作ってて自動メンテに挑戦してみたいと思ったため。
毎度ながら素人の自分でもできる超簡単な方法を採ったので、たぶんもっとセキュアでいい方法はあると思う。
やったこと
Webアプリ側
自作のチャットアプリで1分毎に「test」と自動投稿させてみる。
rails側でこういうアクションを書く。
def create_test_comment Comment.create(content: 'test') end
ルーティングでアプリURL/testにアクセスすれば上のアクションが実行されるよう設定。
CentOS側
$ crontab -u [ユーザ名] -e
エディタが起動されるので、
*/1 * * * * curl http://example.com/test
と入力して保存。
あとは自動実行をわくわくして見守る。
うまくいってることを確認。
同じ要領で「テーブルのレコードが◯件を超えた分を削除」とか定期実行させられそう。