Home>

When I set the environment variable to the activeadmin page, it was not set properly, so when I execute db: seed, an error occurs.
Since the administrator account of activeadmin is described in the seed file, if this cannot be executed, the account will not be created and it is a problem.
Is there a way to solve this?

The errors that occur on the terminal are as follows.

Access denied for user'root' @'localhost' (using password: YES)
Corresponding source code

seed.rb

unless AdminUser.find_by (email: ENV ['KEY'])
  AdminUser.create! (Email: ENV ['KEY'], password: ['SECRET_KEY'], password_confirmation: ['SECRET_KEY']) if Rails.env.development?
end
# Below this is the code to create the product name


database.yml

default:&default
  adapter: mysql2
  encoding: utf8
  pool:<% = ENV.fetch ("RAILS_MAX_THREADS") {5}%>
  username: root
  password: password:
  socket: /tmp/mysql.sock
development:
<<: * default
  database: reservation_system_development
  email:<% = ENV ['KEY']%>
  password:<% = ENV ['SECRET_KEY']%>
  password_confirmation:<% = ENV ['SECRET_KEY']%>
test: test:
<<: * default
  database: reservation_system_test
production:
<<: * default
  database: reservation_system_production
  username: reservation_system
  password:<% = ENV ['reservation_system_DATABASE_PASSWORD']%>
  email:<% = ENV ['KEY']%>
  password:<% = ENV ['SECRET_KEY']%>
  password_confirmation:<% = ENV ['SECRET_KEY']%>


gitignore

/.env.production
/.env.development


admin_user

class AdminUser</pre>
<p><br />
active_admin</p>
<pre><code data-language = "Ruby">ActiveAdmin.setup do | config |
  config.site_title = "Reservation System"
  config.authentication_method =: authenticate_admin_user!
  config.current_user_method =: current_admin_user
  config.logout_link_path =: destroy_admin_user_session_path
  config.root_to ='reservations # index'
  config.comments = false
  config.comments_menu = false
  config.batch_actions = true
  config.filter_attributes = [: encrypted_password,: password,: password_confirmation]
  config.localize_format =: long
end
What I tried

(1) By typing the following from the console, the desired data could be output.

  • ENV ['KEY']
  • ENV ['SECRET_KEY']
    (2) If i comment out the following 3 lines of database.yml and execute db: seed, it will be "Validation failed: Please enter Password with 6 characters or more".
email:<% = ENV ['KEY']%>
  password:<% = ENV ['SECRET_KEY']%>
  password_confirmation:<% = ENV ['SECRET_KEY']%>
Supplementary information (FW/tool version, etc.)

We are using a Gem called Dotenv.

  • Answer # 1

    It is abnormal that databawe.yml has email or password_confirmation.
    username: password: In some cases host: socket :.