Ruby slim - class for div from variable

I know this post here:

Ruby Slim - How do you define an element class using a helper or the rails variable?

and I tried all three solutions. For me, unfortunately, none of them work.

forum.rb

.panel .panel-heading .span = @forum.name .panel-body .row .col-md-7 #{t('global.topic')} .col-md-3.value.title .col-md-1.value.topic .col-md-1.value.date 

forum_feed.js.coffee

 window.ForumFeedUI = flight.component -> @defaultAttrs titleSelector: '.value.volume' topicSelector: '.value.topic' dateSelector: '.value.date' @refresh = (event, data) -> @update @select('volumSelector'), data.volume @update @select('topicSelector'), data.topic @update @select('dateSelector'), data.date 

Everything works as expected when I want to print variables as text on a website. However, I need divs that also contain a variable for the name. No matter what I try, I cannot get the divs class with a header variable.

I believe that I need to create a helper element in these lines and content_tag:

 content_tag(:div, content_tag(:p, "Hello world!"), class: "strong") div = t(".#{forum_title title}") def forum_title(title, &block) content_tag :div, class: "col-md-3-#{title}" do capture(&block) end end 
+6
source share
2 answers

you can try:

 .col-md-7 class="your-#{dynamic class}" 
+9
source

Use alternate notation [] for css attributes.

These three lines are equivalent:

 .col-md-6.title#foo Some content div.col-md-6.title#foo Some content div[class="col-md-6 title" id="foo"] Some content 

In the latter case, you can put the Ruby #{} in quotation marks, so you can do this:

 - myclass = "col-md-6" div[class="#{myclass} title" id="foo"] 

And IMO is the simplest answer.

+1
source

Source: https://habr.com/ru/post/974735/


All Articles