I want to add devise in Rails, but I can't bundle install

Since an error occurred when building the environment with docker and adding gems I will share information as a memorandum!

Development environment

docker rails (5.2.0) ruby (2.7.1) mysql (5.7) nginx puma

error contents

When I added the devise gem in the Gemfile and ** docker-compose run --rm rails bundle install **, the following error occurred

~ RailsApp % docker-compose run --rm rails bundle install              
Starting railsapp_db_1 ... done
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Bundler could not find compatible versions for gem "railties":         
  In snapshot (Gemfile.lock):
    railties (= 5.2.4.3)

  In Gemfile:
    devise (= 4.1.0) was resolved to 4.1.0, which depends on
      railties (< 5.1, >= 4.1.0)

    rails (~> 5.2.2) was resolved to 5.2.4.3, which depends on
      railties (= 5.2.4.3)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

I didn't know what was the cause, but for the time being, it said, "** bundle update ** may solve it." ** run docker-compose run --rm rails bundle update **

↓↓↓↓↓↓↓↓

~ RailsApp % docker-compose run --rm rails bundle update           
Starting railsapp_db_1 ... done
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...........................
Bundler could not find compatible versions for gem "railties":      
  In snapshot (Gemfile.lock):
    railties (= 5.2.4.3)

  In Gemfile:
    devise (= 4.1.0) was resolved to 4.1.0, which depends on
      railties (< 5.1, >= 4.1.0)

    rails (~> 5.2.2) was resolved to 5.2.4.3, which depends on
      railties (= 5.2.4.3)

It didn't work ...

Cause

From the conclusion, it seems that the cause of the error was that the gem ** devise was not in the list. ** **
I referred to the following article. https://qiita.com/hatorijobs/items/2928e152f22d009b07d0

If you execute this article as it is, it will be solved, but if you are working with docker, there are some commands It's different, so I'll explain it here.

Workaround

Operate in the following order.

1. docker-compose exec [Arbitrary service name]Check the gem list with the gem list and make sure there are no devise gems.

2. docker-compose exec [Arbitrary service name]Install devise with gem install devise.

3.Docker again-compose exec [Any service name]Check the gem list with gem list and devise(4.7.2)Make sure there is.

4.In Gemfile**gem 'devise','4.7.2'Describe

5. docker-compose run --Run rm rails bundle update

Let's look at them in order. ↓↓↓↓↓↓↓↓

** 1. Check the list of gems with docker-compose exec [arbitrary service name] gem list, and make sure that there is no devise gem. ** **

~ RailsApp % docker-compose exec app gem list
  
*** LOCAL GEMS ***

actioncable (5.2.4.3, 5.2.2)
actionmailer (5.2.4.3, 5.2.2)
actionpack (5.2.4.3, 5.2.2)
actionview (5.2.4.3, 5.2.2)
actionjob (5.2.4.3, 5.2.2)

~abridgement~

web-console (3.7.0)

** 2. Install devise with docker-compose exec [arbitrary service name] gem install devise. ** **

~ RailsApp % docker-compose exec app gem install devise
Fetching warden-1.2.8.gem
Fetching bcrypt-3.1.13.gem

~abridgement~

Successfully installed devise-4.7.2
5 gems installed

** 3. Check the list of gems with docker-compose exec [arbitrary service name] gem list again, and confirm that devise (4.7.2) exists. ** **

~ RailsApp % docker-compose exec app gem list
  
*** LOCAL GEMS ***

actioncable (5.2.4.3, 5.2.2)
actionmailer (5.2.4.3, 5.2.2)
actionpack (5.2.4.3, 5.2.2)
actionview (5.2.4.3, 5.2.2)
actionjob (5.2.4.3, 5.2.2)

~abridgement~

devise (4.7.2)

~abridgement~

web-console (3.7.0)

** 4. Write gem'devise', '4.7.2' in Gemfile **

Gemfile.


source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.2.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server

~abridgement~

#Addition of login function
gem 'devise','4.7.2'

~abridgement~

** 5. Run docker-compose run --rm rails bundle update **

~ RailsApp % docker-compose run --rm rails bundle update

If there is no error with this, we win

What I noticed

I've noticed some things when dealing with errors, so I'll share them.

docker-Running compose exec app gem install devise will install the latest version of gem.
We have decided that there is no problem with the latest version, so we have omitted the explanation of how to specify the version.
* If you know how to do it, please let me know!

By the way, I found a site where all version history of devise is posted, so I will link the URL. https://rubygems.org/gems/devise/versions


[Any service name]What is docker-compose.This is the service name specified in yml.
It can be decided arbitrarily, but it seems that there are many people who set it on the web such as db or app on any site.

At the end

Regarding Rails and docker, I will continue to post articles about errors regularly for output. Also, I think there were some points that I couldn't reach in my first post, but thank you for reading to the end! !! !!

that's all

Recommended Posts

I want to add devise in Rails, but I can't bundle install
[Rails] How to install devise
I want to use a little icon in Rails
I want to authenticate users to Rails with Devise + OmniAuth
I want to define a function in Rails Console
[Rails] Add column to devise
Super easy in 2 steps! How to install devise! !! (rails 5 version)
[Rails] Add strong parameters to devise
How to install Swiper in Rails
When you have introduced devise but want to add more columns
I don't see an error in Rails bundle install ... the solution
[Rails] I want to add data to Params when transitioning with link_to
I want to install PHP 7.2 on Ubuntu 20.04.
I can't install rails on my mac
[Rails] I can post S3 images in my local environment, but I can't switch to S3 on Heroku.
I want to use @Autowired in Servlet
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I tried to organize the session in Rails
Error in bundle install when running rails new
I want to use arrow notation in Ruby
I want to pass APP_HOME to logback in Gradle
rsync4j --I want to touch rsync in Java.
How to conditionally add html.erb class in Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
[Rails] Added in devise: username not added to database
[Ruby on Rails] How to install Bootstrap in Rails
[Rails] I want to load CSS with webpacker
I want to get the value in Ruby
I want to use Combine in UIKit as well.
I want to do something like "cls" in Java
I want to embed any TraceId in the log
I can't overwrite information on columns in rails console ...
Introduce devise in Rails to implement user management functionality
[Ruby] I can't install puma on Mac [Rails, etc.]
[Rails] I want to display the link destination of link_to in a separate tab
I want to stop snake case in table definition
I want to add a reference type column later
I want to click a GoogleMap pin in RSpec
I want to add a delete function to the comment function
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
After posting an article with Rails Simple Calendar, I want to reflect it in the calendar.
I changed the Ruby version and now I can't bundle install
When I changed to M1 mac, bundle install became impossible
[Rails] [bootstrap] I want to change the font size responsively
I want to push an app made with Rails 6 to GitHub
I was addicted to setting default_url_options with Rails devise introduction
I want to perform high-speed prime factorization in Ruby (ABC177E)
I want to create a form to select the [Rails] category
A story I was addicted to in Rails validation settings
I want to manually send an authorization email with Devise
I want to transition to the same screen in the saved state
I want to simplify the conditional if-else statement in Java
I want to convert characters ...
(For beginners) [Rails] Install Devise
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
I can't log in to MySQL from Django when using docker-compose
I tried to implement Ajax processing of like function in Rails