How to add a CSS class to a partial rendered in Rails -
i have multiple partials rendering , add css class 1 of them. there way this?
here page rendering
<%= render :partial => "/account/plan_yearly" -%>
which adds html page
<div class="offer"> <!--more html--> </div>
what this:
<%= render :partial => "/account/plan_yearly", :class => "highlight" -%>
which render html below:
<div class="offer highlight"> <!--more html--> </div>
but doesn't work way want to. thoughts? appreciated!
thanks
you need render partial using locals , use them within partial:
<%= render partial: "/account/plan_yearly", locals: { myclass: 'highlight' } %>
what make local variable named myclass
value of 'highlight' scope of partial.
so in partial can make use of this:
<div class="offer <%= myclass %>"> <!--more html--> </div>
Comments
Post a Comment