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

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

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

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

Docker

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

Q&A

1回答

1673閲覧

docker + railsでdeviseをインストールすることができたがrails g devise:viewsとrails g devise Userが反応しない

moriyama0525

総合スコア6

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

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

Docker

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

0グッド

0クリップ

投稿2020/02/12 11:01

編集2020/02/12 12:59

#現在の状況
環境はdocker toolboxです。
railsでログイン機能をつけるためにdevise gemをGemfileに追記し

docker

1docker-compose build

をしました。

config/locals/devise.en.ymlと
config/initializers/devise.rbが追加されていることは確認しました。

次にconfig/environments/development.rbにconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }を追加し
end

config/environments/development.rb

1Rails.application.configure do 2 # Settings specified here will take precedence over those in config/application.rb. 3 4 # In the development environment your application's code is reloaded on 5 # every request. This slows down response time but is perfect for development 6 # since you don't have to restart the web server when you make code changes. 7 config.cache_classes = false 8 # Do not eager load code on boot. 9 config.eager_load = false 10 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 11end 12 # Show full error reports. 13 config.consider_all_requests_local = true 14 15 # Enable/disable caching. By default caching is disabled. 16 if Rails.root.join('tmp/caching-dev.txt').exist? 17 config.action_controller.perform_caching = true 18 19 config.cache_store = :memory_store 20 config.public_file_server.headers = { 21 'Cache-Control' => 'public, max-age=172800' 22 } 23 else 24 config.action_controller.perform_caching = false 25 26 config.cache_store = :null_store 27 end 28 29 # Don't care if the mailer can't send. 30 config.action_mailer.raise_delivery_errors = false 31 32 config.action_mailer.perform_caching = false 33 34 # Print deprecation notices to the Rails logger. 35 config.active_support.deprecation = :log 36 37 # Raise an error on page load if there are pending migrations. 38 config.active_record.migration_error = :page_load 39 40 # Debug mode disables concatenation and preprocessing of assets. 41 # This option may cause significant delays in view rendering with a large 42 # number of complex assets. 43 config.assets.debug = true 44 45 # Suppress logger output for asset requests. 46 config.assets.quiet = true 47 48 # Raises error for missing translations 49 # config.action_view.raise_on_missing_translations = true 50 51 # Use an evented file watcher to asynchronously detect changes in source code, 52 # routes, locales, etc. This feature depends on the listen gem. 53 config.file_watcher = ActiveSupport::EventedFileUpdateChecker 54end 55

次にconfig/routes.rbを編集し

routes.rb

1Rails.application.routes.draw do 2 root to: "home#index" 3 resources :foods 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5end

としapplication.html.erbに

<p class="notice"><%= notice %></p> <p class="alert"><%= alert %></p>

を追加し

application.html.erb

1<body> 2 <nav class="navbar navbar-default"> 3 <div class="container-fluid"> 4 <!-- Brand and toggle get grouped for better mobile display --> 5 <div class="navbar-header"> 6 <a class="navbar-brand" href="/foods">Health & Muscle delivery</a> 7 </div> 8 <%= link_to "メニュー一覧", foods_path %> 9 <%= link_to "メニューの追加", new_food_path %> 10 <button type="button" class="btn btn-default navbar-btn">Sign in</button> 11 </div> 12 </nav> 13 <p class="notice"><%= notice %></p> 14 <p class="alert"><%= alert %></p> 15 <%= yield %> 16 </body>

としたところまで完了しています。

#エラー・詰まっているところ
上記の操作を行い、docker-compose コマンドを打とうとしたら

docker-compose run --rm web rails g devise:views
docker-compose run --rm web rails g devise User

イメージ説明

このように操作が何も行われないまま、終了してしまっています。よろしくお願いします。

不足している情報があれば教えてください。

追加
docker-compose.yml

docker

1version: '3' 2services: 3 web: 4 build: . 5 command: bundle exec rails s -p 3000 -b '0.0.0.0' 6 volumes: 7 - .:/app 8 ports: 9 - 3000:3000 10 depends_on: 11 - db 12 tty: true 13 stdin_open: true 14 db: 15 image: mysql:5.7 16 volumes: 17 - db-volume:/var/lib/mysql 18 environment: 19 MYSQL_ROOT_PASSWORD: password 20volumes: 21 db-volume:

Dockerfile

dockerfile

1FROM ruby:2.4.5 2RUN apt-get update -qq && apt-get install -y build-essential nodejs 3RUN mkdir /app 4WORKDIR /app 5COPY Gemfile /app/Gemfile 6COPY Gemfile.lock /app/Gemfile.lock 7RUN bundle install 8COPY . /app

お願いします。

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

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

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

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

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

kazto

2020/02/12 12:27

docker-compose.yml、およびweb/Dockerfileの内容を追記してください。ここのコメントにではなく、質問を修正する形でおねがいします。
guest

回答1

0

Dockerfile

1COPY Gemfile /app/Gemfile 2COPY Gemfile.lock /app/Gemfile.lock 3RUN bundle install

上記がよくなさそうです。bundle installでインストールおよびGemfile.lockの生成を行う前に、古いファイルをコンテナにコピーしてしまっています。

また、結局docker-compose.ymlで

YAML

1 volumes: 2 - .:/app

とマウントしてしまっているので、ローカルにあるGemfileが優先されてしまい、コンテナに組み込んだファイルは使われていないのではないでしょうか。

問題点はわかりましたが、どう解決するかはもう少し調べないとわからないので、後ほど更新します。

投稿2020/02/12 23:17

kazto

総合スコア7196

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

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

moriyama0525

2020/02/12 23:39

お手数かけてすみません。よろしくお願いします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問