gpt4 book ai didi

css - rails : Can't add CSS class from variable in link_to

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:22 24 4
gpt4 key购买 nike

语法错误发生在:

<% @list1.each do |list| %>
<div class="well well-sm">
<%= list.test_name %> <%= link_to 'Do It', '#', class: <%= list.test_type %>
</div>
<% end %>

也试过 class: <%= #{list}.test_type %>等等……这是怎么回事?

最佳答案

您有多余的 erb 打开标签 <%= ,而是:

<%= list.test_name %> <%= link_to 'Do It', '#', class: <%= list.test_type %>
^^^open close^^ ^^open ^^^open close^^

使用:

<%= list.test_name %> <%= link_to 'Do It', '#', class: list.test_type %>

我建议你阅读 An Introduction to ERB Templating

关于css - rails : Can't add CSS class from variable in link_to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35956581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com