Domanda

I've created a basic Rails engine (I'm using Rails 4), and I've integrated it into my main Rails app via the Gemfile:

gem 'app_core', :path => '../app_core'

I also added that to my Sinatra app, and bundle install said the gem installed there. I'm testing this in my Sintra app like follows:

get '/products.?:format?' do
  AppCore::Product.all.to_json
end

When I do this I get:

NameError at /products
uninitialized constant AppCore::Product

Any ideas how to work around this? Is it possible to integrate an engine into a Sinatra app?

È stato utile?

Soluzione

I was able to get this working using a gem instead of an Engine. I simply could not make Sinatra use a Rails Engine, but it will use a custom gem just fine. So, I added this to the Rails app and Sinatra app Gemfiles:

gem 'app_core', :path => '../app_core'

and then in the Sinatra app main file I had to do this:

require 'bundler/setup'
require 'app_core'

Voila!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top