Reputation: 405
I've created a partial which I'm rendering in my view. I'm using two locals: icon and path.
The issue I'm encountering is that I don't know how to pass the following parameters:
"About", "https://www.google.com", target: "_blank", class: "medium button radius", id: "about_us"
to the path local.
Any help/tips, greatly appreciated.
Code without locals
_footer.html.erb
<div class="footer">
<div class="row">
<div class="small-12 columns">
<div class="footer-icon">
<span><%= fa_icon “home” %></span>
</div>
<div class="footer-button">
<%= link_to "About", "https://www.google.com",
target: "_blank", class: "medium button radius",
id: "about_us" %>
</div>
</div>
</div>
</div>
about.html.erb
<% content_for :footer_class do %>
<% render partial: 'layouts/footer', %>
<% end %>
Code with locals
_footer.html.erb
<div class="footer">
<div class="row">
<div class="small-12 columns">
<div class="footer-icon">
<span><%= fa_icon icon %></span>
</div>
<div class="footer-button">
<%= link_to path %>
</div>
</div>
</div>
</div>
about.html.erb
<% content_for :footer_class do %>
<% render partial: 'layouts/footer', locals: {icon: "home", path: ? } %>
<% end %>
Upvotes: 1
Views: 923
Reputation: 6942
You could build a hash and access the values in the view:
about.html.erb
<% path_hash = {
label: "About",
destinatoin: "https://www.google.com",
target: "_blank",
class: "medium button radius",
id: "about_us"
} %>
<% content_for :footer_class do %>
<% render partial: 'layouts/footer', locals: {icon: "home", path_attrs: path_hash } %>
<% end %>
Then in _footer.html.erb
<div class="footer-button">
<%= link_to path_attrs[:label], path_attrs[:destination], target: path_attrs[:target], id: path_attrs[:id], class: path_attrs[:class] %>
</div>
Not sure why you're doing it this way in the first place. Seems like it could get messy over time, but this should do the trick for you.
Upvotes: 1