I'm working on an infrastructure for Rails application and I'm trying to take something out of someones existing project. I am sort of new to rails but I read the guides on plugins and engines ect..
So I have a gemified Engine, containing some module. I have a model say SharedPost trying to extend said module and I'm getting the uninitialized constant error
uninitialized constant Stake::SharedPost
Here's some of what my engine looks like:
#file: lib/stake/shared_post.rb
module Stake
module SharedPost
...
end
end
#file: lib/stake/engine.rb
module Stake
class Engine < ::Rails::Engine
isolate_namespace Stake
end
end
And in the main app I've got
#file: Gemfile
...
gem 'stake'
...
#file: config/routes.rb
Pop::Application.routes.draw do
root :to => 'home#index'
mount Stake::Engine, :at => '/stake'
end
#file: app/models/posted.rb
class Posted < ActiveRecord::Base
extend Stake::SharedPost
...
end
end
The main application will load, though with no available data on it. While I try to run
rake db:seed
for example when trying to load the Posted model I get the error uninitialized constant Stake::SharedPost
What am I missing to get access to my gem's namespaced modules?
EDIT: I've read into the acts_as pattern and that doesn't seem to be the cleanest way of doing things, plus I'm not sure how to implement that onto my engine. Is there another solution?
In lib/stake.rb
are you including the lib/stake/shared_post.rb
file?
It should look something like this:
# file lib/stake.rb
require "stake/shared_post.rb"
module stake
....
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.