简体   繁体   English

Ruby on rails - 每个都做类?

[英]Ruby on rails - each do class?

<% consents_checkboxes.each do |checkbox| %>
  <%= checkbox.html_safe %>
<% end %>

Hello there,你好呀,

can i give them a class while looping through them?我可以在循环时给他们上课吗? I can't get it to work and tried several different ways.我无法让它工作并尝试了几种不同的方法。

This is something I would like to achieve这是我想要实现的目标

<% consents_checkboxes.each do |checkbox| %>
  <%= checkbox.html_safe, class: 'checkbox' %>
<% end %>

thank you谢谢你

You can only do it with an element.你只能用一个元素来做。 What you want to do is:你想要做的是:

<% consents_checkboxes.each do |checkbox| %>
   <p class="checkbox"><%= checkbox.html_safe %></p>
<% end %>

Of course, you can use another element (span, div etc.).当然,您可以使用其他元素(span、div 等)。

What's on consents_checkboxes? permits_checkboxes 上有什么? You should provide more context when you ask for something...当您要求某事时,您应该提供更多背景信息...

It looks like you have strings with the html code, right?看起来您有带有 html 代码的字符串,对吗? you will have to parse the string with something like nokogiri and add a class你将不得不用类似 nokogiri 的东西解析字符串并添加一个类

<%= Nokogiri.parse(checkbox).add_class('checkbox') -%>

Or you could modify the process that generates that consents_checkboxes to include the class you need.或者,您可以修改生成该 permits_checkboxes 的过程以包含您需要的类。 Maybe there's better options, but with only that information it's really hard to tell.也许有更好的选择,但只有这些信息真的很难说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM