Reputation: 2946
This is a topic.gemspec
:
Gem::Specification.new do |s|
s.name = 'topic'
s.version = '1.0.0'
s.date = '2012-12-30'
s.files = ["lib/models/topic.rb"]
end
The gem is located in my application root.
in Gemfile:
gem 'topic', :path => '.'
While running the app, I can't see the topic class.
uninitialized constant ApplicationController::Topic
What am I doing wrong?
Thanks.
Upvotes: 0
Views: 71
Reputation: 16730
I highly recommend you place your gem in it's own directory as Yves mentions.
But you can also have other issues, lets try a few things:
It's seems you are trying to use Topic inside a controller, and maybe it's not searching outside? :s Try to use ::Topic
instead. :: tells to look at the "root" so it wont search a ApplicationController::Topic
If that does not work maybe you don't have a namespace in your gem. I think bundle or whatever requires the namespace (module) named the same way as the gem so you should have:
# in topic/lib/topic.rb
module Topic
end
#require other parts of the gem
require 'topic/foo'
require 'topic/bar'
Hope I could help
Upvotes: 0
Reputation: 1996
You should make sure that bundler required your gem. You should have a file lib/topic.rb
. Add a puts
statement and check if it is shown when you boot your app or the console.
As a side note. I don't think you should have a gemspec in the root of your directory. This will lead to the fact that your lib folder is used for the gem and for the rails app. It's better to create a subfolder for example topic/
and then host the gem inside. You can then add it in the Gemfile with:
gem 'topic', :path => './topic'
Upvotes: 1