我正在Rails 6中做一个实验项目,这个项目的目的是学习新的方法&使用新的(Ish)技术。
据我所知,StimulusReflex & ViewComponentReflex期望反射类驻留在reflexes文件夹/命名空间中。
我想要达到的目标:
将我的ViewComponentReflex组件嵌套在Trailblazer概念文件夹(命名空间)中。
我尝试过的:
创建了以下文件夹结构:
concepts/post/component/counter.rbclass Component::Counter < ApplicationComponent
def initialize
@loading = false
end
def loading=(new_value)
@loading = new_value
refresh! '#loader'
end
def do_expensive_action
prevent_refresh!
self.loading = true
wait 20
self.loading = false
end
endconcepts/post/component/counter/counter.html.erb<%= component_controller do %>
<div id="loader">
<% if @loading %>
<p>Loading...</p>
<% end %>
</div>
<button type="button" data-reflex="click->Component::Counter#do_expensive_action" >Load Content</button>
<% end %>预期结果:
我希望Rails允许使用名称空间等。当设置上面的程序&运行一个示例应用程序时,我会得到错误:uninitialized constant Component::CounterReflex。这个阶级的信赖是建立在一个宝石,但我不知道在哪里找到它。我尝试过在ViewComponentReflex中重写一些方法,但没有结果。
当我将Component::Counter移动到components文件夹(如这个例子中所示)时,代码可以工作。
是否有任何方法可以使用此堆栈重新定义/配置反射类的路由(模块)?
更新:
我的应用程序的GitHub存储库可以是在这里发现的
我在点击“计数器”按钮时看到的确切错误消息是:
StimulusReflex::Channel is streaming from StimulusReflex::Channel
06:48:27 log.1 | StimulusReflex::Channel#receive({"target"=>"Component::Counter#do_expensive_action", "args"=>[], "url"=>"http://krated.test/", "attrs"=>{"type"=>"button", "data-reflex"=>"click->Component::Counter#do_expensive_action", "data-key"=>"6b36d7d05b8737b0328d19bd2fff2679901b1736bb9e242b128e3b715aba6e87", "data-controller"=>"stimulus-reflex", "data-action"=>"click->stimulus-reflex#__perform", "checked"=>false, "selected"=>false, "tag_name"=>"BUTTON", "value"=>""}, "dataset"=>{"data-reflex"=>"click->Component::Counter#do_expensive_action", "data-key"=>"6b36d7d05b8737b0328d19bd2fff2679901b1736bb9e242b128e3b715aba6e87", "data-controller"=>"stimulus-reflex", "data-action"=>"click->stimulus-reflex#__perform"}, "selectors"=>[], "reflexId"=>"a091247b-d53b-4e63-ac59-78c72c4a3cb1", "permanent_attribute_name"=>"data-reflex-permanent", "params"=>{}})
06:48:27 log.1 | StimulusReflex::Channel Failed to invoke Component::Counter#do_expensive_action! http://krated.test/ uninitialized constant Component::CounterReflex /Users/hermann/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.3/lib/active_support/inflector/methods.rb:284:in `const_get发布于 2020-10-08 10:17:38
view_component_reflex的2.3.5版期望组件类名以Component结尾。如果他们不这么做,那就失败了。请参阅反射/工程#L18
因此,再次尝试调用组件:
Component::CounterCountComponenthttps://stackoverflow.com/questions/64219483
复制相似问题