I'm learning Ruby on Rails, and having lots of difficulty setting up.
So I have created this new app, using 'rails new' command.
Modified a bit, and now on way to deploy it on heroku.
First try, it failed because heroku required the app to use postgresql rather than sqlite3, which was set as a default database.
So I downloaded and installed postgresql, and here is the where the trouble began.
After installing the postgres, I set up the path.
And then I was unable to run the app locally anymore.
In command, "rails server" command is not working anymore, showing all kinds of error not being able to load stuff.
It looks like this:
D:\ruby\appname>rails server
c:\RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:10:in 'require': cannot load such file --2.1/pg_ext <LoadError>
and another bunch of load error.
No need to mention deploying on heroku, it fails everytime.
After installing postgresql, I can't use any database related commands as it says "loaderror" everywhere.
I can't run the app locally, nor deploy on heroku.
How should I fix this database problem?
In development you can still use SQLite, and in production use Postgres.
It's not advisable forever to have that disparity, but it does mean you an make progress.
Remove any production settings in database.yml, but still include 'pg' in your Gemfile.
Heroku will automatically insert database settings for Postgres in production. Deploy and then run heroku run rake db:migrate to set up your database.
Related
I've been working on a Ruby on Rails API and I'm using Google Cloud Platform, specifically Google App Engine, to deploy my app. I followed the instructions here. So far so good. My app was successfully deployed and I could successfully run the migrations. Let's call this environment production.
The thing is I need to deploy a sort of staging environment. For the moment I had to create another project to solve my problem and consider that as my staging environment. Now, I don't think this is necessary, actually seems to be redundant.
I've prepared another database my_app_db_staging. And I created a staging.yaml file stating to run as another instance with the service name staging. The service was successfully deployed. Where is the problem? Well, running the migration. I'm using the appengine gem. So, to run the migrations you're supposed to run:
bundle exec rake appengine:exec -- bundle exec rake db:migrate
But as the documentation states:
The appengine gem provides the Rake task appengine:exec to run a command against the most recent deployed version of your app in the production App Engine environment.
So, no clue on how to run the migrations against my recently created staging service.
I looked deeper into the appengine gem, and it has an option. It lacks more documentation so you don't have to waste time looking for an answer:
rake appengine:exec GAE_CONFIG=staging.yaml -- bundle exec rake db:migrate
The options can work together with GAE_SERVICE, but the yaml file has to have the same name, otherwise you'll get an error.
I'm trying to create a new record through the rails console but I'm getting the following error:
PG::ConnectionBad: FATAL: database "my_database_development" does not exist
I've recently changed from Sqlite3 to PG to be able to deploy to Heroku. Is this what is giving the error?
Thanks a lot!
It looks like you have not yet run
rake db:create
This will "create" the databases on your PostgreSQL server. A step that you didn't have to do with SQLite, but Postgres requires it. As TK-421 said, make sure that your database.yml is configured for your OS and Postgres, not SQLite.
Here is a (possibly outdated) Railscast on the topic.
http://railscasts.com/episodes/342-migrating-to-postgresql
Is this running locally, or on Heroku? In config/database.yml, the local user you specify will need to have CREATEDB privileges (as a superuser, for example).
There's a little more configuration required in this case than for SQLite. Google will show you a bunch of tutorials specific to your OS.
If you see this problem in production on heroku, start the console like this:
rails console production
If you have that problem in development on your machine, check your config/database.yml. It is points to a local development database that does not exist.
Using capistrano I'm deploying my Rails 4 app under the environment name "staging". When I ssh onto the server and run rails console, any ActiveRecord queries I do come up with no such table. So I check my Rails.env and sure enough it reads development instead of staging. But even running rails console staging, it does set Rails.env to "staging", but still the ActiveRecord queries say no such table. The app itself is running fine (under Apache and Passenger), but for some reason the rails console is unable to connect to the db.
I've reverted back to when I knew it was working and am still seeing the error, which tells me it is a configuration change i must've made on the server as opposed to a change to the rails app code or capistrano deploy config.
OK, tracked down the answer myself. The RAILS_ENV was originally being set to staging in /etc/environment -- but a while ago this file was removed during some debugging, and not restored.
What does still surprise me is that
rails console staging
does not have the same effect as
export RAILS_ENV=staging
rails console
anyhow, sorted.
I'm currently evaluating Nitrous.io and liking what I'm seeing so far. I've currently got a few databases for testing and development running on Heroku's hosted Postgresql service as well. I'm running into some issues when running tests though, and I'm hoping somewhere here may have a solution.
When I run rake db:test:prepare I'm getting the error:
FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
From what I've read elsewhere, that's trying to DROP the database, but Heroku's hosted databases don't allow that. Does anyone out there know how to run Rails tests on Heroku's Postgresql?
Nitrous.IO has released a package manager which will allow you to install Postgres within your Nitrous box. This can be used for your test database as well as your development database if needed:
https://github.com/action-io/autoparts
This also requires that you are using a Nitrous box is running version "bran" or later (see README). You may need to terminate/create a new box if you are running on version "arya".
To use autoparts, run parts search to see all of the packages available.
To install postgresql within the Nitrous box, run the following command:
parts install postgresql
Make sure that your config/database.yml file explicitly sets host: localhost for each database you wish to connect to, or else the pg adapter will fail to find the socket it needs to connect to.
According to the Heroku docs, you need to use "heroku pg:reset" in your rake task.
https://devcenter.heroku.com/articles/rake
I have now my rails 3.2.1 app running on Heroku.
I've tried to upload the database to mongohq via the heroku mongo:push command, after installing the heroku mongo plugin.
https://github.com/pedro/heroku-mongo-sync
I get the message asking me to confirm if I want to push, but once the push is done, there is nothing my db.
I'm not sure if it is a problem with heroku or if i'm missing a step.
Could it be that i need to put my app in production mode and migrate the database to production?
I'm not sure how to do that either.
Cheers
does your local heroku connection conform to the plugins assumptions [in the readme's config section]? if not you'll have to set it via:
export MONGO_URL = mongodb://user:pass#localhost:1234/db
i'll also note, that even after doing this i had to uninstall the heroku plugin and reinstall it from this fork: http://github.com/fjg/heroku-mongo-sync.git
heroku plugins:install http://github.com/fjg/heroku-mongo-sync.git
Check out the MongoSync Ruby Gem
It's a gem I wrote for that very purpose when I had to constantly copy my Local MongoDB database to and from my Production DB for a Project (I know it's stupid). It's extremely easy to use. Once you've entered your DB details in the mongo_sync.yml file, you can push and pull DBs using these rake tasks:
$ rake mongo_sync:push # Push DB to Remote
$ rake mongo_sync:pull # Pull DB to Local
Note: It's also available as shell script for non-ruby apps: mongo-sync