Is it possible include Nesta CMS into Rails3 application?

坚强是说给别人听的谎言 提交于 2019-11-30 14:19:09

问题


I'd like "to mount" a Nesta CMS app onto a Rails3 app This should be possible couse of being Nesta a Sinatra 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 ?


回答1:


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




回答2:


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"


来源:https://stackoverflow.com/questions/3867491/is-it-possible-include-nesta-cms-into-rails3-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!