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? |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.
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_to
calls thelink_to
helper 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_to
to output the HTML rather than return it. You don’t expect to have to pass it tounsafe_raw
yourself.To help with this,
phlex-rails
provides an adapter for every Rails helper. These adapters are provided as modules to include in your components as needed — though it proba…