Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails中添加条件类?_Ruby On Rails - Fatal编程技术网

Ruby on rails 如何在rails中添加条件类?

Ruby on rails 如何在rails中添加条件类?,ruby-on-rails,Ruby On Rails,我是新来的:/,试图创建一个动态博客,问题是我试图根据其中的字数更改div ID。。有时会出现“无法将fixnum与字符串进行比较”错误,有时还会出现语法错误 <style> #smalldiv { width: 100px; background-color: red; height: 150px; } #largediv { width:300px; background-color: green; height: 150px; } </style> #斯莫迪夫{

我是新来的:/,试图创建一个动态博客,问题是我试图根据其中的字数更改div ID。。有时会出现“无法将fixnum与字符串进行比较”错误,有时还会出现语法错误

<style>
#smalldiv {
width: 100px;
background-color: red;
height: 150px;
}
#largediv {
width:300px;
background-color: green;
height: 150px;
}
</style>

#斯莫迪夫{
宽度:100px;
背景色:红色;
高度:150像素;
}
#拉格迪夫{
宽度:300px;
背景颜色:绿色;
高度:150像素;
}
邮务主任

class PostsController < ApplicationController
def index
@posts = Post.all
end
end
class PostsController
Posts\u视图

<% @posts.each do |x| %>
<div id = '<%= 'smalldiv' if x.description.size < '50' + 'largediv' if x.description.size > '50' %>' >
<p> <% x.description %> </p>
</div>
<% end %>

您需要使用
试试


你有。。。引号在50左右,如果一行中有太多的
语句,您的
中缺少
=
,谢谢我更改了它,但它并没有解决我的问题看起来我的语法错误或缺少什么东西..非常感谢,它很有效,看起来这些引号让我:)脱离主题,但html
id
在单个html文档中应该是唯一的。在这里使用
class
可能更有意义,您的css将从
#smalldiv
更改为
。smalldiv
非常感谢您的反馈。。。你是完全正确的,下次我一定会考虑到这一点。。。非常感谢