Sinatra Warden with existing Ruby on Rails application that uses Devise

后端 未结 1 986
孤独总比滥情好
孤独总比滥情好 2021-01-03 04:36

I am trying to split my current Ruby on Rails 3 web-application and it\'s web-services (API). My web-application is running on Heroku and implements API as a namespaced rout

相关标签:
1条回答
  • 2021-01-03 05:12

    I was able to get it working. There were a few main aspects:

    • Get Devise working with Rails (Devise is a Rails app, won't work without it)
    • Setup the mapping (route) on Rack level to support both Rails and Sinatra
    • Share the sessions between Rails and Sinatra
    • Setup Warden and make it available to Sinatra

    Here is most relevant part of code from /config.ru:

        #
    
        # ...
    
        # Rest with Rails
        map "/" do
          run MyApp::Application
        end
    
        # Anything urls starting with /slim will go to Sinatra
        map "/slim" do
    
          # make sure :key and :secret be in-sync with initializers/secret_store.rb initializers/secret_token.rb
          use Rack::Session::Cookie, :key => '<< see, initializers/secret_store.rb >>', :secret => '<< copy from initializers/secret_token.rb >>'
    
          # Point Warden to the Sinatra App
          use Warden::Manager do |manager|
            manager.failure_app = AppMain
            manager.default_scope = Devise.default_scope
          end
    
          # Borrowed from https://gist.github.com/217362
          Warden::Manager.before_failure do |env, opts|
            env['REQUEST_METHOD'] = "POST"
          end
    
          run AppMain
        end
    

    See, http://labnote.beedesk.com/sinatra-warden-rails-devise for a complete solution.

    0 讨论(0)
提交回复
热议问题