-
Notifications
You must be signed in to change notification settings - Fork 245
Integrated Toto and a Rails app in 10 steps.
For a longer discussion see Integrating toto and Rails
Toto works great if your existing rails application needs a blog. Here’s how to do it.
1.) cd your_rails_app
2.) mkdir blog
3.) cd blog
4.) git clone git://github.com/cloudhead/dorothy.git .
5.) merge the contents of the dorothy .gems file with the .gems file in the root of your rails application.
6.) remove the files needed for a standalone toto install
rm README
rm Rakefile (you may want to merge the toto rakefile with your rails rakefile to take advantage of the “new” task for creating new posts.
rm config.ru
rm .gems
rm -rf public
rm -rf .git
7.) cd .. (back to the root of your rails app)
8.) create a Rack config file, config.ru, in your rails root.
9.) Open config.ru in your favorite text editor and add the following
require 'toto'
require 'config/environment.rb'
#point to your rails apps /public directory
use Rack::Static, :urls => [‘/stylesheets’, ‘/javascripts’, ‘/images’, ‘/favicon.ico’], :root => ‘public’
use Rack::ShowExceptions
use Rack::CommonLogger
#run the toto application
toto = Toto::Server.new do
#override the default location for the toto directories
Toto::Paths = {
:templates => “blog/templates”,
:pages => “blog/templates/pages”,
:articles => “blog/articles”
}
#set your config variables here
set :title, “Your Blog Title”
set :date, lambda {|now| now.strftime(“%B #{now.day.ordinal} %Y”) }
set :summary, :max => 500
set :root, “blog”
if RAILS_ENV != ‘production’
set :url, “http://localhost:9292/blog/”
else
set :url, “http://your-blog.heroku.com/blog/”
end
end
#create a rack app
app = Rack::Builder.new do
use Rack::CommonLogger
#map requests to /blog to toto
map ‘/blog’ do
run toto
end
#map all the other requests to rails
map ‘/’ do
if Rails.version.to_f >= 3.0
ActionDispatch::Static
run Rails.application
else # Rails 2
use Rails::Rack::Static
run ActionController::Dispatcher.new
end
end
end.to_app
run app
10.) run your app to test it with “rackup” and then deploy it to heroku with git push heroku master.