-
-
Save don-smith/403483 to your computer and use it in GitHub Desktop.
a rails mongo_mapper template when using heroku's mongohq addin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rails_heroku_mongohq_template.rb | |
# | |
# fork of Kyle Banker's Rails MongoMapper Template (http://gist.github.com/219223) | |
# and modified to work with heroku's mongohq addon. | |
# | |
# To use: | |
# rails project_name -m http://gist.github.com/403483.txt | |
# (preface with 'sudo' if you think you might need some gems) | |
# remove unneeded defaults | |
run "rm public/index.html" | |
run "rm public/images/rails.png" | |
# might reconsider in the future | |
run "rm public/javascripts/controls.js" | |
run "rm public/javascripts/dragdrop.js" | |
run "rm public/javascripts/effects.js" | |
run "rm public/javascripts/prototype.js" | |
# add basic layout to start | |
file 'app/views/layouts/application.html.erb', <<-HTML | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
<head> | |
<title>Application!</title> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script> | |
<%= stylesheet_link_tag 'application' %> | |
</head> | |
<body> | |
<h1>google analytics id not set</h1> | |
<%= yield %> | |
<script type="text/javascript"> | |
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | |
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); | |
</script> | |
<script type="text/javascript"> | |
try { //uncomment next 2 lines to turn on | |
//var pageTracker = _gat._getTracker("UA-#######-#"); | |
//pageTracker._trackPageview(); | |
} catch(err) {}</script> | |
</body> | |
</html> | |
HTML | |
# MongoDB FTW! | |
db_name = ask('What should I call the database? ') | |
initializer 'mongo.rb', <<-CODE | |
if ENV['MONGOHQ_URL'] | |
MongoMapper.config = {RAILS_ENV => {'uri' => ENV['MONGOHQ_URL']}} | |
else | |
MongoMapper.config = {RAILS_ENV => {'uri' => 'mongodb://localhost/#{db_name}'}} | |
end | |
MongoMapper.connect(RAILS_ENV) | |
CODE | |
file 'config/database.yml', <<-CODE | |
# Using MongoDB | |
CODE | |
# Don't need ActiveRecord | |
environment 'config.frameworks -= [:active_record]' | |
# MongoMapper against MongoHq on Heroku | |
gem 'bson', :version => '1.0' | |
gem 'jnunemaker-validatable', :lib => 'validatable', :version => '1.8.4' | |
gem 'mongo', :version => '1.0' | |
gem 'plucky', :version => '0.1.1' | |
gem 'mongo_mapper', :version => '0.7.6' | |
# Testing Helper | |
file 'test/test_helper.rb', <<-CODE | |
ENV['RAILS_ENV'] = 'test' | |
require File.expand_path(File.dirname(__FILE__) + '/../config/environment') | |
require 'test_help' | |
require 'shoulda' | |
require 'mocha' | |
require 'factory_girl' | |
class ActiveSupport::TestCase | |
# Drop all collections after each test case. | |
def teardown | |
MongoMapper.database.collections.each do |coll| | |
coll.remove | |
end | |
end | |
# Make sure that each test case has a teardown | |
# method to clear the db after each test. | |
def inherited(base) | |
base.define_method teardown do | |
super | |
end | |
end | |
end | |
CODE | |
# Testing tools | |
gem 'redgreen' | |
gem 'shoulda' | |
gem 'factory_girl' | |
gem 'mocha' | |
# Gem management | |
rake 'gems:install' | |
rake 'gems:unpack' | |
rake 'rails:freeze:gems' | |
# source control | |
file '.gitignore', <<-FILES | |
.DS_Store | |
**/.DS_Store | |
log/* | |
tmp/* | |
tmp/**/* | |
config/database.yml | |
coverage/* | |
coverage/**/* | |
FILES | |
git :init | |
git :add => '.' | |
git :commit => '-a -m "Initial commit"' | |
# decide what heroku commands to include here | |
# heroku create db_name | |
# heroku addons:add mongohq:free | |
# heroku addons:add custom_domains:basic | |
# heroku addons:add zerigo_dns:basic | |
# heroku addons:add newrelic:bronze | |
# git push heroku master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOT tested yet ... just an idea ... to finish is on my todo list