Ruby Slim - How do you define an element's class with a rails helper or variable?
How about
div[class="sample #{@variable.name}"]
or even
div class=["sample", @variable.name]
or
.sample *{:class => [@variable1.name, @variable2.name]}
Ruby slim - class for a div from variable
you could try:
.col-md-7 class="your-#{dynamic class}"
rails variable within div class name
You need to use an erb tag in your erb templates:
<div class="<%= my_class_name %>">
Forward slash in a Slim classname?
Slim doesn't support forward slashes in class names.
I think there is the only one way for it: div class="w-1/3"
Slim with embedded Ruby
A tag followed by text will output that text as the tag's contents. You can use string interpolation #{expression}
inside the text to output variables.
Content text with a variable interpolated:
title #{yield(:title)} | Ruby on Rails Tutorial Sample App
You can also set the tag's contents to a ruby expression by using tag =
.
title = yield(:title) + " | Ruby on Rails Tutorial Sample App"
Note that in this case this won't work if yield(:title)
returns nil
When you have nested tags, you should put them on seperate lines.
slim dynamic conditional class
See the examples below:
div class=(is_active? ? 'active' : 'inactive')
div class=('active' if is_active?)
The same approach can be used to assign dynamic values to other attributes.
Proper syntax for including a ruby variable in an Ajax call inside a SLIM view
Use this:
'/users_activities?email=#{@user.email}'
Slim Syntax for Inline Div/Table Classes with Embedded Ruby
The doc for this feature is here:
td class="#{@article.attribute}"
Slim: Append text to printed Ruby variable
Figured it out .. I just had to do:
a href = data.api.docs+"#some-subsection" Clicky
.. to generate:
<a href="https://docs.example.com/api#some-subsection">Clicky</a>
Related Topics
How to Display Text, a Dotted Line Then More Text Spanning the Width of the Page
Arabic Characters from HTML Content to PDF Using Itext
CSS Text Underlining Too Long When Letter-Spacing Is Applied
Understanding Grid Negative Values
Add Outward Curving Border to Elements Like This: ◝◟_◞◜
How to Change the Inner White Color of Font Awesome's Exclamation Triangle Icon
Are Self-Closing Input Tags Valid in HTML 4
Center Navbar Links Without Brand Pushing It to the Right in Bootstrap 4
Open a Direct File on the Hard Drive from Firefox (File:///)
When I Try to Shift the Image Upwards Using Negative Margin the Whole Container Is Moved Upwards
Why Should One Add Id to Their HTML Tags
Some Elements Missing While Downloading from Httpwebrequest
Chrome Getusermedia Not Requesting Permission Locally
How to Create a Slanted Background with CSS
How to Set the HTML Options for Collection_Select in Rails
How to Make Sure That My Footer Shows All the Way at End of the Page Rather Than in the Middle