Component helper methods aren't included in remote renders
devonwalshe opened this issue · 4 comments
A component that uses a helper method defined in its associated helper module returns a NoMethodError
, when a controller action is called via ajax with a remote: true
call.
# /components/foo_component/foo_component.html.haml
=button_to foo_helper("foo"), foo_path, remote: true
# /components/foo_component/foo_component.rb
Module FooComponent
extend ComponentHelper
def foo_helper(text)
return text
end
end
# /app/controllers/foos_controller.rbs
...
def foo
render partial: 'components/foo_component/foo_component'
end
If the helper method is included in the app/helpers/foo.rb
it works just fine.
App is on komponent 1.1.4 & Rails 5.1.
Hi @devonwalshe can you try with version see below2.0.0.pre.1
of Komponent?
Hello @devonwalshe,
Nothing wrong here, you are using render partial
from Rails, not component
helper from Komponent. Only component helper load and inject component module into view context.
You can do what you want with:
def foo
render html: helpers.component("foo")
end
Cheers @florentferry, that indeed worked. Would agree it would be useful if this was documented. Many thanks!
I documented this in the cookbook: https://github.com/komposable/komponent/wiki#cookbook
EDIT: it has been documented in the README as well