我是 ruby on rails 的新手,抱歉,如果这是一个愚蠢的问题。
这里我有一个class=""的例子
class="table table-striped"
下面是一个类的例子:“”
class: "btn btn-primary btn btn-success"
请解释一下它们之间的区别。 谢谢
最佳答案
class="
是一个 HTML 表达式,而 class: "
是一个 Ruby 表达式。
您没有给出您看到这些内容的任何上下文,所以请允许我插入我自己的内容。
假设您有一个 View ,index.html.erb
,具有以下标记:
<table class="table table-striped">
<% @people.each do |person| %>
<tr class="person">
<td><%= person.first_name %></td>
<td><%= person.last_name %></td>
<td><%= person.last_name %></td>
<td><%= link_to 'View', person, class: 'btn btn-default btn-sm' %></td>
</tr>u
<% end %>
</table>
在这里,您可以看到 table
元素具有 table table-striped
类,它们是使用第一种语法在 HTML 中定义的。
另一方面,最后一个 td
调用 Rails 定义的 link_to
帮助程序,并将 class
参数作为 Ruby 散列传递进来。 documentation for link_to
显示该方法采用名为 html_options
的散列,这是 class
参数最终到达的位置。
关于ruby-on-rails - 类="with equal sign in front"和类:"with Colon"的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27894135/