Flo*_*och 8 ruby-on-rails rails-engines rails-cells
我创建了一个引擎,它提供了一个ui组件作为单元格.相应的gem(criteria_operator-ui_component)在lib文件夹中几乎不包含任何代码,因为要使单元格正常运行,我必须在资源路径中工作.gem的基本文件如下所示:
require 'criteria_operator/ui_component/engine'
require 'cells/rails'
module CriteriaOperator
module UiComponent
# Your code goes here...
end
end
Run Code Online (Sandbox Code Playgroud)
引擎不包含太多:
module CriteriaOperator
module UiComponent
class Engine < ::Rails::Engine
require 'jquery-rails'
require 'criteria_operator'
isolate_namespace CriteriaOperator::UiComponent
end
end
end
Run Code Online (Sandbox Code Playgroud)
对我来说,看起来宝石甚至不知道细胞,但据我所知,我不允许在lib文件夹之外包含任何东西.此外,在项目中测试虚拟应用程序中的单元格工作正常.
现在我在一个真正的Rails应用程序中使用这个引擎.在gemfile中,我包括以下内容:
gem 'criteria_operator'
gem 'cells' # i added these three, because `bundler list` didn't show me
gem 'cells-rails' # `cells-rails` and `cells-erb` even though they are listed
gem 'cells-erb' # as dependencies for the engine
gem 'criteria_operator-ui_component'
Run Code Online (Sandbox Code Playgroud)
我登上了路线
mount CriteriaOperator::UiComponent::Engine => '/criteria_operator-ui_component'
Run Code Online (Sandbox Code Playgroud)
并尝试使用CriteriaOperator::UiComponent::CriteriaEditor像我在虚拟应用程序中所做的那样的单元格.里面的erb:
cell('criteria_operator/ui_component/criteria_editor', @op)
Run Code Online (Sandbox Code Playgroud)
或者来自代码:
include Cell::RailsExtensions::ActionController
def whatever
cell(CriteriaOperator::UiComponent::CriteriaEditor, @op).call()
end
Run Code Online (Sandbox Code Playgroud)
错误是ActionView::Template::Error (uninitialized constant CriteriaOperator::UiComponent::CriteriaEditor).
我究竟做错了什么?我在使用引擎时只是遗漏了什么,或者引擎本身是否以错误的方式实现?如果是这种情况,为什么虚拟应用程序有效?我完全陷入困境,这是我第一次创建Rails引擎以及我第一次使用单元格...
您正在调用CriteriaOperator::UiComponent::CriteriaEditor,但该类/模块似乎不存在。
CriteriaOperator::UiComponent::Engine工作正常,因为它是在引擎本身中定义的。
我猜你的示例应用程序可以工作,因为它使用基于视图的调用,就像cell('criteria_operator/ui_component/criteria_editor')它可能与 JavaScript 一起工作一样?如果不将单元定义为这样的类,则无法使用“代码”版本:
https: //github.com/trailblazer/cells#cell-class
| 归档时间: |
|
| 查看次数: |
178 次 |
| 最近记录: |