I am trying to get my application online and functioning with Heroku.
The application uses MongoHQ and Mongoid.
I have read multiple guides that just say to add this, "uri: <%= ENV['MONGOHQ_URL'] %>" to the mongoid.yml file, but it's not working for me.
This is the error I get from Heroku,
"Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details."
This is what it's in my $ heroku logs
2011-03-12T21:09:57-08:00 heroku[router]: Error H10 (App crashed) -> GET autommator.heroku.com/ dyno=none queue=0 wait=0ms service=0ms bytes=0 2011-03-12T21:09:57-08:00heroku[nginx]: GET / HTTP/1.1 | 76.112.220.158 | 795 | http | 503
Here is my mongoid.yml file.
require 'yaml'
YAML::ENGINE.yamler= 'syck'
defaults: &defaults
host: localhost
# slaves:
# - host: slave1.local
# port: 27018
# - host: slave2.local
# port: 27019
development:
<<: *defaults
host: localhost
database: autommator_development
test:
<<: *defaults
host: localhost
database: autommator_test
# set these开发者_运维百科 environment variables on your prod server
production:
uri: <%= ENV['MONGOHQ_URL'] %>
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
Completely out of ideas.
Thanks.
To use mongoid with the Heroku add-on, your mongoid.yml should look like this:
production:
uri: <%= ENV['MONGOHQ_URL'] %>
You shouldn't have any other database connection information there, so pull out the host, port, username, password and database fields.
I figured out the problem this morning. My app on my development PC is running Ruby 1.9.2. Heroku defaults to 1.8.7.
I just ran the commands found in this article, http://devcenter.heroku.com/articles/bamboo reloaded, and everything works.
Thanks for the help guys.
Did you create the database through the Heroku addon or directly from MongoHQ? If you did it directly from MongoHQ then you will need to set the variables manually.
heroku config:add MONGOHQ_URL=mongodb://user:pass@server.mongohq.com:port/db_name
If it was via the heroku addon then it should be created for you. If adding the variable doesn't help send us a support ticket to support@mongohq.com and we can dig further.
Maybe I'm stating the obvious here, but what that's doing is pulling the values of those from the environment. In order for that to work, you would need to have set the variables (MONGOHQ_URL, etc) in the heroku environment. I think the command for that is something like heroku config:add MONGOHQ_URL=XXXXX
or something like that. Definitely look it up in the heroku docs.
Given that you're getting the values out of the environment, though, the YML seems the wrong way to go. I suggest and initializer file that just sets these value, or puts them into some sort of MONGO_CONFIG where you can read them anywhere. If you go this route, you could also set them to the env variables if preset, or fall back to the YML file if not.
This railscast shows kind of what I'm talking about http://railscasts.com/episodes/85-yaml-configuration-file The difference is that when it comes time to set the variable, you set it to ENV['XXX'] if ENV['XXX']
精彩评论