简体   繁体   English

创建rails 3 gem:Gems安装成功,但是没有功能

[英]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. 我正在尝试用珠宝商创建我的第一个rails宝石-这是一个非常简单的演示宝石,仅带有“ Tester”模型和“ Frog”支架。

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. 宝石包就好了,宝石内容“ testgem”确认了所需的文件已打包到宝石中,当我“捆绑安装”它时,一切似乎都可以了,宝石就在已安装宝石的列表中。

...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. 不能从命令行识别activerecord模型(命令“ Tester”返回“未初始化的常数Tester”),即使我手动将资源添加到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}/ /*]. 我尝试将必要的文件放置在[GEM_ROOT] / lib / app /和[GEM_ROOT] / app /中,并将gem.path设置为[{lib} / / ,{app} / / *]。

Any suggestions most appreciated. 任何建议,不胜感激。 ;-) ;-)

Ach - terribly embarrassing - 30 mins after posting I figured it out. Ach-非常尴尬-发布后30分钟,我发现了。

In case anyone else is wondering: In the gem, I wasn't directing the mygemname.rb file to the engine.rb file. 万一其他人想知道:在gem中,我没有将mygemname.rb文件定向到engine.rb文件。 In short, I needed 简而言之,我需要

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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