I'd like "to mount" a Nesta CMS app onto a Rails3 app This should be possible couse of being Nesta a Si开发者_Python百科natra app, which should be a Rack mountable layer, ... but how would you do it ? Where will you start from ? Does anybody has experiences on this topic ? Suggested docs ?
Hey Luca. I've been meaning to write this up a for a month or two. You just need to mount Nesta as a Rack app, using Rails Metal.
Have a watch of this:
http://railscasts.com/episodes/222-rack-in-rails-3
You'll be able to refer to Nesta in your routes by referring to it as Nesta::App (I only merged the commit that allows you to do this into master a week or so ago, so make sure you're up to date with the latest code on github). In order to make that work, all you should need to do is to require Nesta's app.rb file.
I'm yet to try this with Rails 3 myself, but I've been doing it for a while with Rails 2. If you have any trouble, ping me on the mailing list (nesta@librelist.com).
For people wondering how to achieve the same thing with Rails 2.3, I've been using code that looks like this (in lib/nesta_metal.rb):
require File.join(File.dirname(__FILE__), *%w[.. vendor nesta app])
class NestaMetal
def initialize(app)
@app = app
end
def call(env)
status, headers, response = Nesta::App.call(env)
(status == 404) ? @app.call(env) : [status, headers, response]
end
end
Cheers,
Graham
Here's the code I used to make it work on my app:
MyRailsApp::Application.routes.draw do
mount MyNestaSite.new => "/blog"
match '/' => "static#welcome" # and whatever other rails routes you want
end
At the time it also required the latest version of Sinatra from github as the version available via rubygems had a bug in how it handled environment variables, so I added this to my Gemfile:
gem "sinatra", :git => "http://github.com/sinatra/sinatra.git"
精彩评论