ruby-on-rails - 安装生成器不会看到我定义的方法

标签 ruby-on-rails ruby-on-rails-4 mongoid rails-engines forem

我正在尝试在另一个应用程序中使用我的引擎来测试安装生成器,但它似乎失败了。我已经很长时间没有使用我的安装生成器了,所以我不确定它什么时候坏了(或者它是否真正顺利地工作过)。我的项目基于 radar/forem,所以我尝试借用他们的很多代码(包括生成器)。

编辑:我的安装程序适用于引擎测试/虚拟,但不适用于其他应用程序。为什么?

GH 问题:https://github.com/NJayDevelopment/mongoid_forums/issues/16

这是日志:

$ rails g mongoid_forums:install
What is your user class called? [User] 
What is the current_user helper called in your app? [current_user] 
Defining mongoid_forums_user method inside ApplicationController...
      insert  app/controllers/application_controller.rb
Adding mongoid_forums initializer (config/initializers/mongoid_forums.rb)...
      create  config/initializers/mongoid_forums.rb
(erb):5:in `template': undefined method `per_page' for MongoidForums:Module (NoMethodError)
The route is successfully added, however the initializer/mongoid_forums.rb is a blank file. The method is defined exactly how radar/forem does it, what could be the error?

相关代码如下:

每页方法定义:https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L33

Mattr 访问器: https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/mongoid_forums.rb#L9

初始化模板: https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install/templates/initializer.rb

在错误点安装生成器: https://github.com/NJayDevelopment/mongoid_forums/blob/master/lib/generators/mongoid_forums/install_generator.rb#L47

最佳答案

事实证明,当您尝试在 pry 中要求 mongoid_forums 时,您会看到涉及装饰器的错误发生。这个问题在我对装饰者的拉取请求中得到解决:parndt/decorators#13

这是因为需要文件的方式以及那里调用 load! 的方式。

等待 PR 状态,这与 radar/forem 使用的版本相同。

关于ruby-on-rails - 安装生成器不会看到我定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29553299/

相关文章:

ruby-on-rails - 使用 Dragonfly 在 Rails 中保存大文件时应用程序超时

ruby-on-rails - 反向代理不将查询字符串传递给应用程序

mysql - Rails 4应用程序中多个数据库之间的切换

ruby-on-rails - 两个独立的 has_many 表

ruby-on-rails - 自定义404无法从 Controller 触发

ruby-on-rails - Font Awesome Rails 在部署后将无法工作。它看起来像是糟糕的 Unicode 字符。为什么?

ruby-on-rails - 将 Activerecord 数据库迁移到 Mongoid

ruby-on-rails - 为什么我的 mongoDB 托管 mongoid.yml 的 uri 设置无法正常工作?

heroku - Heroku 上的 Rails 4 应用程序中未初始化的常量 Moped::BSON

ruby-on-rails - 抑制 Rails 模式加载