提问人:German 提问时间:9/9/2023 更新时间:9/9/2023 访问量:40
如何根据 Rails 视图中的值动态设置 HTML 元素的左边距值?
How to dynamically set the margin-left value of a an HTML element based on a value in the Rails view?
问:
My Rails 应用程序生成嵌套注释并使用变量跟踪其深度。我可以看到这个变量正在生成适当的值,因为我可以使用这段代码在comment_layout视图中读取它,但是,当我尝试使用它来设置我在相关中使用它时的值时,它没有给我任何结果,如下所示:depth
<%= comment.depth %>
margin-left
<div>
<div class="c-margin" style="margin-left: <%= comment.depth * 4 %>px;">
<%= comment.depth %>
<%= comment.body %>
</div>
我无法解释这里可能有什么问题。对任何能指出我哪里出错的人都非常有义务。
答: 暂无答案
下一个:禁用的表单输入不会显示在请求中
评论
style="margin-left: <%= comment.depth * 4 %>px !important;"
comment.depth
!important