Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Connecting local Rails app to remote database

rails databases remote connect link

  • Please log in to reply
6 replies to this topic

#1 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 18 August 2013 - 07:47 PM

Hello all...

 

I am a Rails newbie.  I created a database on my server (bluehost).  I have installed rails app through the servers cpanel.  Now, how can I connect my rails project which I have created on my computer to that remote database.  All the tutorials I have seen show how to create a localhost database in mysql, which is great, but how do I link it to that database?  I believe I have to edit the database.yml file, but am unsure how to.  Can anyone please help.  

 

Thank you....



#2 Ohm

Ohm

    Guard

  • Members
  • 179 posts
  • LocationCopenhagen

Posted 18 August 2013 - 08:48 PM

You normally do not want to develop with production data, which is why so many suggest that you create a local database whilst developing.

 

That being said, it is possible to connect to a remote database from your development environment.

You just edit the database.yml file so that the development scope points to the production database:

production: 
  adapter: postgresql
  encoding: utf-8
  pool: 5
  username: "username"
  password: "password"
  host: "hostname"
  port: "port number"
  database: "database name"


Blog: http://ohm.sh | Twitter: madsohm


#3 Figgy

Figgy

    Passenger

  • Members
  • 7 posts

Posted 18 August 2013 - 08:59 PM

Ohm thank you south for the response. Makes total sense not working on a production model. So if I work on my local one, once I'm ready to test it on the remote database, is it as simple as exporting the SQL and importing it to the remote server? Hope that makes sense lol...SQL newbie as well.

#4 Ohm

Ohm

    Guard

  • Members
  • 179 posts
  • LocationCopenhagen

Posted 18 August 2013 - 09:03 PM

People do this differently. Some write seed data for their development database (this is best practice) and some just grab a dump of the latest production database and import that into their development. 

 

You shouldn't ever want to import data from your development database to your production one. If you mean schema, like setting up the tables and such, that's what Rails migrations are for. You just run those migrations on your production database as well.


Blog: http://ohm.sh | Twitter: madsohm


#5 Ohm

Ohm

    Guard

  • Members
  • 179 posts
  • LocationCopenhagen

Posted 18 August 2013 - 09:05 PM

production: 
  adapter: mysql
  encoding: utf-8
  pool: 5
  username: "username"
  password: "password"
  host: "hostname"
  port: "port number"
  database: "database name"

 

I just noticed that you wrote "mysql" in your post, so of course the adapter from my previous post must be mysql


Blog: http://ohm.sh | Twitter: madsohm


#6 Stuart Hannig

Stuart Hannig

    Signalman

  • Members
  • 15 posts

Posted 19 August 2013 - 12:56 AM

If you are looking to experiment with PostgreSQL, may I suggest Heroku Postgres? Quite easy to setup the database.yml to be used as test and dev databases, and even production if you need it. It's pretty much free as long as you don't go overboard on too much data in the database, so pretty easy to just monkey around with.


  • Kelli Shaver likes this

#7 Kelli Shaver

Kelli Shaver

    Inspector

  • Administrators
  • 75 posts
  • LocationKentucky

Posted 19 August 2013 - 06:45 PM

You may need to also go into the Bluehost cPanel and enable remote connections. It's been so long since I had anything to do with anything hosted there, though, that I can't remember. There is usually an option in the cPanel MySQL settings, though, where you can enter an IP whitelist.

 

If you want some easy options for local databases, as Stuart mentioned, Heroku's Postgress.app is great if you want to give it a try. If you want MySQL locally, it's pretty simple to install via Homebirew, or you could even download MAMP, start it up, and just connect to the SQL server and ignore that whole PHP bit. ;)







Also tagged with one or more of these keywords: rails, databases, remote, connect, link

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users