简体   繁体   中英

Creating rails 3 gems: Gems installing successfully, but no functionality

I'm trying to create my first rails gem with jeweller - it's a very simple demo gem with just a "Tester" model and a "Frog" scaffold.

The gem packages up just fine, gem contents "testgem" confirms the desired files are packaged into the gem, and when I "bundle install" it, everything seems to go OK & the gem is in the list of installed gems.

...BUT - I'm not getting any functionality. The activerecord model isn't recognised from the command line (Command "Tester" returns "uninitialized constant Tester"), and the controllers aren't being found either, even when I manually add the resources to config/routes.

This is my first self-built gem, so I could be missing something simple. I've tried placing the necessary files in both [GEM_ROOT]/lib/app/ and [GEM_ROOT]/app/ , with gem.path set to [{lib}/ / , {app}/ /*].

Any suggestions most appreciated. ;-)

Ach - terribly embarrassing - 30 mins after posting I figured it out.

In case anyone else is wondering: In the gem, I wasn't directing the mygemname.rb file to the engine.rb file. In short, I needed

require 'mygemname/engine' if defined?(Rails)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM