Is it possible include Nesta CMS into Rails3 application?

前端 未结 2 1049
陌清茗
陌清茗 2021-01-01 05:12

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 woul

相关标签:
2条回答
  • 2021-01-01 05:24

    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

    0 讨论(0)
  • 2021-01-01 05:35

    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"
    
    0 讨论(0)
提交回复
热议问题