I'm trying to take an array value and assign it to a div class.
我尝试取一个数组值并将它赋给一个div类。
-values.each do |values|
%p= values[0]
%p= values[1]
Results in what you would expect. Proving that values[0] and values[1] contain data and they are working.
产生你所期望的结果。证明值[0]和值[1]包含数据并且它们正在工作。
I fiddled around with it trying different things and this is as close as I can get:
我摆弄着它,尝试着不同的东西,这是我能做到的最接近的:
-values.each do |values|
- div = values[1]
-.div= values[0]
Which then throws this error:
然后抛出这个错误:
undefined method `div=' for "day":String
undefined method ' div=' for "day":String。
And the string "day" is in values[1]
字符串“day”的值为[1]
Any Ideas?
什么好主意吗?
2 个解决方案
#1
4
- values.each do |value|
%div{ :class => value[1] }= value[0]
#2
2
You should be using this
你应该用这个
-values.each do |values|
%div= values[1]
.div= values[0]
The first one will be a div and the second a div with class div. The reason it says undefined method is because anything after the '-' is executed as ruby and you are basically doing this
第一个是div,第二个是div,它表示未定义的方法是因为“-”之后的任何东西都是作为ruby执行的,你基本上就是这样做的。
values[1].day = values[0]
and there is no method day= for the string "day"
字符串"day"没有method day=
#1
4
- values.each do |value|
%div{ :class => value[1] }= value[0]
#2
2
You should be using this
你应该用这个
-values.each do |values|
%div= values[1]
.div= values[0]
The first one will be a div and the second a div with class div. The reason it says undefined method is because anything after the '-' is executed as ruby and you are basically doing this
第一个是div,第二个是div,它表示未定义的方法是因为“-”之后的任何东西都是作为ruby执行的,你基本上就是这样做的。
values[1].day = values[0]
and there is no method day= for the string "day"
字符串"day"没有method day=