My link_to is not working. #609
|
I'm trying to use link_to like this, but nothing is rendered on html response. Someone knows what could be? |
Replies: 1 comment
|
Hey, we already figured this out in the Naming Things Discord, but in case someone else finds this, I’ll answer here. The trick is to use the adapters rather than going through the In Phlex, you would expect a helper like To help with this, The class MyComponent < ApplicationComponent
include Phlex::Rails::Helpers::LinkTo
def template
link_to(root_path) { "Home" }
end
end |
Hey, we already figured this out in the Naming Things Discord, but in case someone else finds this, I’ll answer here.
The trick is to use the adapters rather than going through the
helpers“proxy”, which is much lower-level.helpers.link_tocalls thelink_tohelper directly and that helper returns HTML. This is because it's designed to be used with<%= %>output ERB tags.In Phlex, you would expect a helper like
link_toto output the HTML rather than return it. You don’t expect to have to pass it tounsafe_rawyourself.To help with this,
phlex-railsprovides an adapter for every Rails helper. These adapters are provided as modules to include in your components as needed — though it proba…