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

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

新規登録して質問してみよう
ただいま回答率
85.47%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby on Rails 6

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

109閲覧

devise_forのルーティングが記述されない(bin/rails db:migrate RAILS_ENV=developmentエラー)

Makaron

総合スコア1

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby on Rails 6

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

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2024/04/16 11:48

実現したいこと

ruby 3.1.4
rails 6.1.7.7
macOS Big Sur 11.7.10
docker 24.0.6

Rails6アプリにて、docker環境でdeviseを導入しましたが、

docker-compose exec web rails g devise User

でdevise_forのルーティングが自動で追加されないため、何かアドバイスをいただきたく思い投稿いたしました。

発生している問題・分からないこと

docker-compose exec web rails g devise User

を行ったところ、

# Migrations are pending. To resolve this issue, run: # # bin/rails db:migrate RAILS_ENV=development # # You have 1 pending migration:

と出てしまいます。
このマイグレートできていないファイルというのはrails g devise Userで作ったものなので問題ないかと思い、メッセージ通りbin/rails db:migrate RAILS_ENV=developmentを行っても、

devise_for

のルーティングが作成されません。

docker-compose exec web bundle install

docker-compose build

docker-compose exec web rails g devise:install

docker-compose exec web rails g devise User

docker-compose exec web bin/rails db:migrate RAILS_ENV=development

docker-compose exec web rails g devise:views User

docker-compose exec web rails g devise:controllers users

の順で行い、ルーティング以外は作成しているように思います。
ファイル一覧
ファイル一覧
ファイル一覧

エラーメッセージ

error

1$ docker-compose exec web rails g devise User 2Running via Spring preloader in process 70 3 invoke active_record 4 create db/migrate/20240414025949_devise_create_users.rb 5 create app/models/user.rb 6 invoke rspec 7Running via Spring preloader in process 79 8Migrations are pending. To resolve this issue, run: 9 bin/rails db:migrate RAILS_ENV=development 10You have 1 pending migration: 1120240414025949_devise_create_users.rb 12While loading rails_helper an `exit` / `raise SystemExit` occurred, RSpec will now quit. 13Failure/Error: abort e.to_s.strip 14SystemExit: 15 Migrations are pending. To resolve this issue, run: 16 bin/rails db:migrate RAILS_ENV=development 17 You have 1 pending migration: 18 20240414025949_devise_create_users.rb 1920# -e:1:in `<main>' 21# ------------------ 22# --- Caused by: --- 23# ActiveRecord::PendingMigrationError: 24# 25# 26# Migrations are pending. To resolve this issue, run: 27# 28# bin/rails db:migrate RAILS_ENV=development 29# 30# You have 1 pending migration: 31# 32# 20240414025949_devise_create_users.rb 33# /usr/local/bundle/gems/activerecord-6.1.7.7/lib/active_record/migration.rb:625:in `check_pending!' 34

該当のソースコード

Dockerfile

1FROM ruby:3.1.4-buster 2 3RUN apt-get update -qq && apt-get install -y build-essential nodejs default-mysql-client libmariadb-dev-compat 4RUN apt-get clean && rm -rf /var/lib/apt/lists/* 5 6# Install Node.js 14 7RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - 8RUN apt-get install -y nodejs 9 10RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 11RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list 12RUN apt-get update -qq && apt-get install -y yarn 13 14RUN mkdir /src 15WORKDIR /src 16 17COPY Gemfile /src/Gemfile 18COPY Gemfile.lock /src/Gemfile.lock 19 20RUN bundle install 21 22COPY . /src 23

docker

1version: '3' 2 3services: 4 web: 5 build: 6 dockerfile: Dockerfile 7 context: . 8 command: bundle exec rails s -p 3000 -b '0.0.0.0' 9 ports: 10 - '3000:3000' 11 volumes: 12 - type: bind 13 source: . 14 target: /src 15 depends_on: 16 - db 17 18 db: 19 image: mysql:8.0 20 ports: 21 - '3306:3306' 22 environment: 23 MYSQL_ROOT_PASSWORD: new_root_password 24 volumes: 25 - type: volume 26 source: mysql 27 target: /var/lib/mysql 28 29 webpacker: 30 build: 31 context: . 32 command: bundle exec bin/webpack-dev-server 33 ports: 34 - "8000:8000" 35 36volumes: 37 mysql: 38 vendor_bundle: 39 node_modules: 40 storage: 41

routes.rb

1Rails.application.routes.draw do 2 devise_for :users #手動で足しましたが効かず 3 root to: 'home#top' 4 resources :diaries 5 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 6end 7

Gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '~> 3.1.4' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem 'rails', '~> 6.1.7', '>= 6.1.7.7' 8# Use mysql as the database for Active Record 9gem 'mysql2', '~> 0.5' 10# Use Puma as the app server 11gem 'puma', '~> 5.0' 12# Use SCSS for stylesheets 13gem 'sass-rails', '>= 6' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 5.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23# gem 'bcrypt', '~> 3.1.7' 24 25# Use Active Storage variant 26# gem 'image_processing', '~> 1.2' 27 28# Reduces boot times through caching; required in config/boot.rb 29gem 'bootsnap', '>= 1.4.4', require: false 30 31group :development, :test do 32 gem 'factory_bot_rails' 33 gem 'rspec-rails' 34 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 35 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 36end 37 38group :development do 39 gem 'rubocop-airbnb' 40 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 41 gem 'web-console', '>= 4.1.0' 42 # Display performance information such as SQL time and flame graphs for each request in your browser. 43 # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md 44 gem 'rack-mini-profiler', '~> 2.0' 45 gem 'listen', '~> 3.3' 46 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 47 gem 'spring' 48end 49 50group :test do 51 # Adds support for Capybara system testing and selenium driver 52 gem 'capybara', '>= 3.26' 53 gem 'selenium-webdriver', '>= 4.0.0.rc1' 54 # Easy installation and use of web drivers to run system tests with browsers 55 gem 'webdrivers' 56end 57 58group :production do 59 gem 'pg' 60end 61 62# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 63gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 64 65# devise 66gem 'devise', '~> 4.8', '>= 4.8.1' 67

Gemfile.lock

1GEM 2 remote: https://rubygems.org/ 3 specs: 45 devise (4.9.4) 6 bcrypt (~> 3.0) 7 orm_adapter (~> 0.1) 8 railties (>= 4.1.0) 9 responders 10 warden (~> 1.2.3) 11 diff-lcs (1.5.1) 12 erubi (1.12.0) 13 factory_bot (6.4.6) 14 activesupport (>= 5.0.0) 1516 17PLATFORMS 18 x86_64-linux 19 20DEPENDENCIES 21 bootsnap (>= 1.4.4) 22 byebug 23 capybara (>= 3.26) 24 devise (~> 4.8, >= 4.8.1) 25 factory_bot_rails 26 jbuilder (~> 2.7) 27 listen (~> 3.3) 28 mysql2 (~> 0.5) 29 pg 30 puma (~> 5.0) 31 rack-mini-profiler (~> 2.0) 32 rails (~> 6.1.7, >= 6.1.7.7) 33 rspec-rails 34 rubocop-airbnb 35 sass-rails (>= 6) 36 selenium-webdriver (>= 4.0.0.rc1) 37 spring 38 turbolinks (~> 5) 39 tzinfo-data 40 web-console (>= 4.1.0) 41 webdrivers 42 webpacker (~> 5.0) 43 44RUBY VERSION 45 ruby 3.1.4p223 46 47BUNDLED WITH 48 2.4.10 49

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

当初deviseを最新のバージョンにしていたので、4.8.1に変更しました。(4.9はRails7?)
そうしてやり直したのですが、うまくいかず詰まっています。
deviseが、specsは(4.9.4)に対し、DEPENDENCIES:は(~> 4.8, >= 4.8.1)になっているのもうまくいかない原因の一つだろうとは思っているのですが、bundle installやbuildをしてもここが変わりません。(4.8.xにしたい)
また、手動でdevise_forを書き足してbundle install等しても変わりませんでした。
Dockerfileの設定がおかしいのでしょうか?検索しても同じ現象が起きている方がおらず、お手上げの状態です。

初心者とはいえ知識不足で恐れいりますが、何かお気づきのことがありましたらアドバイスいただけますと幸いです。
よろしくお願いいたします。

補足

そもそも、docker-compose exec web rails g devise Userを行っていきなり

Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development

が出てしまうのが問題だとは思っているのですが、なぜこうなってしまうのかが見当がつきません。dbのリセットなどすれば解消するものでしょうか?

補足
migration履歴

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

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

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

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

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

guest

回答1

0

自己解決

【自己解決】
こちら、
RAILS_ENV=test rails db:drop
RAILS_ENV=test rails db:create
RAILS_ENV=test rails db:migrate
を行ったらできました。
https://teratail.com/questions/229417

以前のマイグレーションがうまくいっていなかった?のかと思います。
大勢での開発だとあまりよろしくない方法かもしれませんが、個人作成のものですので、この方法を取りました。
ひとまずdeivseが作れてよかった…

投稿2024/04/20 06:33

Makaron

総合スコア1

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問