Closed JoseMPena closed 6 years ago
Hello @JoseMPena thanks for the bug report.
It's weird, it should work out of the box. Did you try to restart the server after creating the component?
Which version of Komponent / Rails / Ruby do you use?
Hi @Spone, thanks for your answer. Actually, just found out that (at least in my case) have to restart the Rails server (not even webpack-dev-server) to get the new helper methods working. Looks like an ActionView thing. My versions: Rails 5.2.0.rc1 Ruby 2.4.1
Ok, so it's an autoloading problem.
In the latest version of Komponent, when you run the install generator, it will take care of it automatically (you can update Komponent, run rails generate komponent:install
again and choose to overwrite just the config/application.rb
file).
If you want to do it manually, just add these two lines to config/application.rb
:
config.autoload_paths << config.root.join('frontend/components')
config.i18n.load_path += Dir[config.root.join('frontend/components/**/*.yml')]
And that should fix it :)
As per the README, component helper module should(?) be wired up to the component 'view' right out of the box:
Helpers
If your partial becomes too complex and you want to extract logic from it, you may want to define custom helpers in the
ButtonComponent
module:However, none of the methods defined on my helpers are accessible from the component 'view':
Always returns:
undefined local variable or method 'something' for #<#<Class:0x007fab224dbca8>:0x007fab21b09b58>
Is there any extra configuration I might be missing or it is not behaving as expected?
Thanks