I am newbie with Ruby Rails and here is my problem.
I created a very simple Rails program by this command
rails new freelancer --database=postgresql --javascript=webpack
And I had no error
In this file
config -> locales -> database.yml
I saw 2 files
database: freelancer_test
database: freelancer_development
Then I ran this command
rails db:setup
It showed me this error
Is the server running locally and accepting connections on that socket? Couldn't create 'freelancer_development' database. Please check your configuration. rails aborted! ActiveRecord::ConnectionNotEstablished: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? Caused by: PG::ConnectionBad: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? Tasks: TOP => db:setup => db:create (See full trace by running task with --trace)
I thought that it must created 2 databases freelancer_test and freelancer_development ?
Could you please give me some advices ? Thank you in advance.
A Postgresql server is required and configured properly to run this Rails application. From the error it expects a postgres server running locally. But you can also connect to a standalone DB server remotely.
Your database.yml should contain correct connection info then run the same command again.
It means that you have no PostgreSQL instance running locally.
Two choices:
Either you install it, you can follow this nice tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-postgresql-with-your-ruby-on-rails-application-on-macos
Or you can just use SQLite for you dev environment
Unless you're really need PostgreSQL features for your development, I'd go for the second option, as you're beginner with RoR, you probably want to focus on the development of your app first. Using the default sqlite database requires no dependencies as the database is a text file in the end.
You can create the app with the following command:
rails new freelancer --javascript=webpack
Related
I am newbie with ubuntu and trying to working with this one. And here is my problem.
I create a new program in rails with database by this command
rails new freelancer --database=postgresql
Everthing woking fine, seems I got a postgresql database with rails.
My problem is, I do not know how to connect my database to the dbeaver program, btw, if I run those command rails db:setup and rails db:migrate after connect my database to dbeave program, it can make some new database ?
And finally can you show me how to start and stop the server too ?
Thank you very much.
Your database connection is specified on your config/database.yml, under your project folder, one block for each environment, but by default you will be using development env.
If you haven't done anything else than what you commented (and you did it right hehe), your database should be already created with name freelancer_development, and you just need to connect to it using DBeaber. Create a new connection using PostgreSQL adapter (check out this video) and following data:
Host: localhost
Port: 5432
Database: freelancer_development
User: [YOUR_POSTGRES_USER]
Password: [YOUR_POSTGRES_PASSWORD]
If you don't know your Postgres user. Try with following combinations, if none of them works, you'll need to setup one.
User
Password
postgres
postgres
postgres
[YOUR_UBUNTU_USER_NAME]
To start your Rails server, just run rails s (short for rails server) on your terminal while being inside your project folder, and hit Ctrl+C to stop it.
I am running my Ruby On Rails 5 app on localhost and now, I imported the production database. It's a PostgreSQL database, exported via the pg_dump tool.
When I modified the database.yml file the Rails app and set there the newly created database, I got this error when running the Rails app (tried also to change the port on which the app is running, but it didn't help):
OpenSSL::Cipher::CipherError at /
In the Rails console is not any information about the error.
What is the reason of such an error? I tried to export the database from the staging server and use it on localhost and everything worked fine.
Based on the docs: https://ruby-doc.org/stdlib-2.4.1/libdoc/openssl/rdoc/OpenSSL/Cipher.html#method-i-final
It looks like you don't have the proper encryption key to connect to the production db.
I would guess you either do have the proper one for staging, or staging is running unencrypted.
Here's someone else with the same error caused by an incorrect key: OpenSSL::Cipher::CipherError when running staging DB on local
I am deploying a Rails project on heroku(using jruby).
It is being deployed successfully but I am not able to run:
heroku run rake db:migrate
(I am one of the collaborators of the app and not the owner)
It is throwing an exception:
ActiveRecord::JDBCError: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "54.163.178.100", user "XXXX", database "YYYY", SSL off
After searching over I got one way i.e adding ?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory in DB url, but I am not sure where to add it.
Apart from all this when I try to deploy the same Rails project on my personal account's app it is working fine.heroku run rake db:migrate is getting succeeded.
Can someone please help me with the solution?
External connections to Heroku Postgres require SSL. This isn't an issue of certificate validation. The problem is that you need to enable SSL.
Add
ssl=true
to your JDBC parameters.
I am a beginner.I am trying to launch rails server using the command.But I am getting an error. I tried searching in the google but no results.I will attach a picture of the log I got when I executed that command.
What Mysql error are you getting?
And what is in your config/database.yml?
So far, you have created the folder structure for a Rails app (rails new), then installed all the relevant components (bundle install).
When you start the server (rails server) it starts in "development" mode (you also have "test" mode for unit tests and "production" mode for when your app is live - and each has slightly different options). One of the first things the Rails server tries to do is connect to the database, so it looks in config/database.yml for the database specified in the development section.
So probably, it's trying to connect to a database that doesn't exist yet, with a username and password that are wrong.
First thing to do is to update the username and password in config/database.yml to match your local Mysql server.
Second thing to do is to build the development database; the command for that is "bin/rake db:create" (or "bundle exec rake db:create" if you're on Rails 3.x).
Hopefully that should be enough to get your server started.
How did you setup your rails app?
It seems like maybe you didn't type
bundle install
This command downloads and updates all of your gems. Action View is a rails dependency.
I'm setting up a new computer to use an existing Rails application (Rails 3.2 with Postgres). I installed postgres via homebrew, along with the Lunchy gem as documented here: http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/. No problems getting a user account and starting/running my application. I ran rake db:create:all to create all of the databases. The site works and loads from only one Terminal tab.
When I open a new tab, same location, and try to start the server, I get the following error:
Users/jpetrarca/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize': could not connect to server: No such file or directory (PG::Error)
19:24:39 web.1 | Is the server running locally and accepting
19:24:39 web.1 | connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I don't know why one terminal session would work and another not.
Interestingly, I can start/stop postgres with lunchy from the non-working terminal and it does, in fact, use the same service and turns off the db being accessed from the working terminal (which is expected).
I initially found this problem while trying to run my rspec tests and connect to the test db.