3 months ago
I've built a Rails 8 app which is running fine within a Github codespace, using a Postgres database. I'm now following your "Deploy a Ruby on Rails App" docs page. (I tried once using the Rails template and once without, butw
The deploy from the Railway CLI was successful, and I've used the Dashboard to set the SECRETKEYBASE and RAILSMASTERKEY, and DATABASEURL: I set the value to ${{Postgres.DATABASEPUBLIC_URL}}
However the deploy (or re-deploy) always fails with the same error:
Tasks: TOP => db:prepare
(See full trace by running task with --trace)
bin/rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (ActiveRecord::ConnectionNotEstablished)
Is the server running locally and accepting connections on that socket?
I don't know if I've misunderstood the documentation, or there's something else wrong with the configuration, but everything I've tried hasn't had any effect :(
ⓘ Deployment information is only viewable by project members and Railway employees.
12 Replies
3 months ago
Hello,
This is your current DATABASE_URL
variable's value -
${{Postgres.DATABASE_PUBLIC_URL}}
You have it setup to reference the DATABASE_PUBLIC_URL
of the Postgres
service, now that's syntactically correct, the issue is that you don't have a Postgres database in the project, you can't reference something that doesn't exist.
Seems like you stopped following the guide before step 4, please continue from where you left off -
3 months ago
I added a PostGres database via the CLI and it seemed to be successful:
Project activitymatch linked successfully!
@orangejon ➜ /workspaces/makuma/activity_match (main) $ railway add
> What do you need? Database
> Select databases to add PostgreSQL
Added PostgreSQL to project
@orangejon ➜ /workspaces/makuma/activity_match (main) $
... but it doesn't appear in the Dashboard. I tried redeploying the Rails service but it didn't change anything, same error:
bin/rails aborted!
Database URL cannot be empty
I also repeated all the steps using the Rails template (in a new project: 'awake-purpose') and the Postgres instance is there in the Dashboard, but I get exact same error.
3 months ago
You deployed the database into a completely separate project then what you deployed the Rails app into.
The database needs to be in the same project.
https://docs.railway.com/overview/best-practices#deploying-related-services-into-the-same-project
3 months ago
No I didn't. See the terminal output I copied, it's linked to "activitymatch" which is the same project as the Rails code.
To make it simpler I have now deleted the other projects and just left the project built from the Rails template ("awake-purpose") seeing as that's the only one where the Postgres service appears.
I don't understand what is wrong with this project?
(Also your documentation is pretty confusing, it sounds like the template was maybe added afterwards and the rest of the instructions weren't updated to match)
3 months ago
Hello,
Yes you had the database deployed into a different project, I had a look at the projects to confirm this before mentioning it.
Following the guide, you would end up with an app and database in the same project.
Just followed the guide myself to confirm this, app and database deployed into the same project.
Documentation has separate sections for deploying via CLI, GitHub, or deploying the template, feel free to ignore whatever section doesn't apply to what you want to do!
3 months ago
Is the template only intended for creating a new empty Rails application, not if I have code ready to deploy?
I guess I'll start again following the "Deploy from the CLI" instructions to see if I get a different result this time.
3 months ago
Yes thats correct, templates like the Rails template are intended to get you going from scratch.
3 months ago
Okay, I started a new project from scratch with no template ("activitymatch2"), following the "Deploy from the CLI" section only. The postgres service displays in the Dashboard this time.
However, the error when the Container starts is exactly the same as previously :(
3 months ago
bin/rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (ActiveRecord::ConnectionNotEstablished)
Is the server running locally and accepting connections on that socket?
3 months ago
You need to use DATABASE_URL
in your code, currently your app is trying to connect via a socket.
3 months ago
Ahh yes! I thought that would be overridden in the Railway environment, sorry.
Thanks so much for your help! I'm new to this so it's great to see my app live on port 80 :)
Status changed to Solved brody • 3 months ago