0

Estoy iniciando con Ruby on Rails. seguí esta guia de GoRails, y llegué hasta el paso en donde hay que ejecutar el comando rake db:create,el cual me da un error. el error indica que debo iniciar el servicio de postgres. Bueno, instalé postgres e inicié el servicio, pero aun asi al abrir otra consola y volver a ejecutar el comando rake db:create, sigo con el mismo mensaje. Inicio de servicio postgresql introducir la descripción de la imagen aquí

console app introducir la descripción de la imagen aquí

message introducir la descripción de la imagen aquí

Se añada Contenido de config/database.yml

# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On macOS with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user running Rails.
  #username: myapp

  # The password associated with the postgres role (username).
  #password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myapp_test

# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
#   production:
#     url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
  <<: *default
  database: myapp_production
  username: postgres
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Espero poder comenzar pronto a aprender ruby on rails! Gracias por su ayuda

2
  • ¿Puedes mostrarnos el contenido de config/database.yml?
    – Gerry
    Commented el 25 oct. 2021 a las 16:48
  • Claro @Gerry Este es el contenido de este archivo: default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see Rails configuration guide # guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: myapp_development test: <<: *default database: myapp_test production: <<: *default database: myapp_production username: postgres password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %> Commented el 26 oct. 2021 a las 19:56

1 respuesta 1

0

Al parecer postgresql esta corriendo, te recomendaría lo siguiente, crea la base de datos manualmente entrando a la consola de postgres, esto usando el mismo comando que pusiste en la primera captura (su -u postgres psql psql), estando ya en la consola de postgres ejecutas:

CREATE DATABASE myapp_development;
CREATE USER user_my_app WITH ENCRYPTED PASSWORD 'superpassworddificil';
GRANT ALL PRIVILEGES ON DATABASE myapp_development TO user_my_app;

Y cambiar la sección de development de tu database.yml por algo como

development:
  <<: *default
  database: myapp_development
  host: localhost
  user: user_my_app
  password: superpassworddificil
2
  • Hola @jaime-arroyo-navia creé la bas desde la consola de posgres: postgres=# CREATE DATABASE myapp_development; WARNING: could not flush dirty data: Function not implemented CREATE DATABASE postgres=# CREATE DATABASE myapp_development; ERROR: database "myapp_development" already exists postgres=# CREATE USER user_my_app WITH ENCRYPTED PASSWORD 'superpassworddificil'; CREATE ROLE postgres=# GRANT ALL PRIVILEGES ON DATABASE myapp_development TO user_my_app; GRANT ... Me muestra este error al intentar abrir luego de rails server fe_sendauth: no password supplied te agradezco Commented el 29 oct. 2021 a las 13:13
  • Hola, me equivoqué en el database.yml en vez de pass era password, edité la respuesta. Commented el 30 oct. 2021 a las 19:31

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.