Dockerでrailsの環境構築をしました。
deviseを使ってログイン画面を作ったのですが、userを作ってもuserが作成されず、エラーもでない状況で困っています。
docker-compose run web rails db
を実行してusersテーブルが作成されていることは確認しました。
$ docker-compose run web rails db Starting sample_db_1 ... done psql (9.6.10, server 11.1 (Debian 11.1-1.pgdg90+1)) WARNING: psql major version 9.6, server major version 11. Some psql features might not work. Type "help" for help. myapp_development=# \d List of relations Schema | Name | Type | Owner --------+----------------------+----------+---------- public | ar_internal_metadata | table | postgres public | schema_migrations | table | postgres public | users | table | postgres public | users_id_seq | sequence | postgres (4 rows) myapp_development=#
ログを確認してもActiveRecord
自体は正常に動作しているみたいでエラーが出ないです。
Started GET "/users/sign_up?utf8=%E2%9C%93&authenticity_token=yeemPGlvigsdmx%2F0uObquma4Iw2H7zi6lyM0V4pUtzt46rUG9FF%2Bk8BJEVMjl5gCO%2BZ3y7uJpb9vSFM67kKSaw%3D%3D&user%5Bemail%5D=sample%40gmail.com&user%5Bpassword%5D=[FILTERED]&user%5Bpassword_confirmation%5D=[FILTERED]&commit=Sign+up" for 172.19.0.1 at 2018-11-11 12:56:38 +0000 Processing by Devise::RegistrationsController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"yeemPGlvigsdmx/0uObquma4Iw2H7zi6lyM0V4pUtzt46rUG9FF+k8BJEVMjl5gCO+Z3y7uJpb9vSFM67kKSaw==", "user"=>{"email"=>"sample@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"} Rendering devise/registrations/new.html.erb within layouts/application Rendered devise/shared/_links.html.erb (1.1ms) Rendered devise/registrations/new.html.erb within layouts/application (25.7ms) Completed 200 OK in 290ms (Views: 289.1ms | ActiveRecord: 0.0ms)
しかし、docker-compose run web rails c
でuserをみると何も作成されていない状態です。
$ docker-compose run web rails c Starting sample_db_1 ... done Running via Spring preloader in process 27 Loading development environment (Rails 5.2.1) irb(main):001:0> User.all User Load (3.3ms) SELECT "users".* FROM "users" LIMIT $1 [["LIMIT", 11]] => #<ActiveRecord::Relation []> irb(main):002:0>
Docker-compose.yml
version: '3' services: db: image: postgres volumes: - ./tmp/db:/var/lib/postgresql/data web: build: . command: bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" depends_on: - db
Dockerfile
FROM ruby:2.5 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs postgresql-client RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。