[英]Rails Convert Array of Strings to Unordered List for Flash
So flash notices are being displayed from a CMS we're using so when we flash the design/layout is pretty hard to get to.所以 flash 通知是从我们正在使用的 CMS 中显示的,所以当我们使用 flash 时,设计/布局很难实现。 So anything that I flash will display in that section and the only thing I can really change is the styling.
因此,我 flash 将显示在该部分中的任何内容,我唯一能真正改变的是样式。 Unless I can do in the Layout > Application render flash unless this one page.
除非我可以在 Layout > Application 渲染 flash 除非这一页。
What I have is an array of strings that I'm trying to convert into an unordered list.我所拥有的是一个字符串数组,我试图将其转换为无序列表。 So for example it's showing up like
@fruit = ["Apple", "Banana", "Orange"]
.因此,例如,它显示为
@fruit = ["Apple", "Banana", "Orange"]
。
My thought was to simply do我的想法是简单地做
@fruit.map(&:inspect).join("\n").delete('""')
With the hope of getting带着希望得到
However since it's in the flash there's no discerning line break.但是,由于它位于 flash 中,因此没有明显的换行符。 If I inspect sure enough it's showing multiple lines but lumped within a text.
如果我检查得足够清楚,它会显示多行但集中在一个文本中。
I even went in and did the following thinking it would work:我什至进去做了以下认为它会起作用的事情:
-flash.each do |type, msg|
ul
=content_tag :li, msg, id: "flash_#{type}"
But its actually not breaking the msg up into an unordered list, especially within the ul, and instead doing:但它实际上并没有将味精分解成一个无序列表,尤其是在 ul 中,而是这样做:
<ul></ul>
<li id="flash_error">"Apple Banana Orange"</li>
So is there a way to convert an array of strings into an unordered list for a flash message?那么有没有办法将字符串数组转换为 flash 消息的无序列表?
flash
lets you use primitive types ( string
, array
, hash
, ...) but you need to handle that in the view, if you put an array in it you need to iterate that array. flash
允许您使用原始类型( string
, array
, hash
,...)但是您需要在视图中处理它,如果您将数组放入其中,则需要迭代该数组。
@fruit = ["Apple", "Banana", "Orange"]
flash[:notice] = @fruit
(also, ul
should be outside of flash.each
) (另外,
ul
应该在flash.each
之外)
ul
- flash.each do |type, msg|
- if msg.is_a? Array
- msg.each do |a|
= content_tag :li, a, id: "flash_#{type}"
- else
= content_tag :li, msg, id: "flash_#{type}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.