I'm trying a helper method that will output a list of items, to be called like so:
foo_list( ['item_one', link_to( 'item_two', '#' ) ... ] )
I have written the helper like so after reading Using helpers in rails 3 to output html:
def foo_list items content_tag :ul do items.collect {|item| content_tag(:li, item)} end end
However I just get an empty UL in that case, if I do this as a test:
def foo_list items content_tag :ul do content_tag(:li, 'foo') end end
I get the UL & LI as expected.
I've tried swapping it around a bit doing:
def foo_list items contents = items.map {|item| content_tag(:li, item)} content_tag( :ul, contents ) end
In that case I get the whole list but the LI tags are html escaped (even though the strings are HTML safe). Doing content_tag(:ul, contents.join("\n").html_safe )
works but it feels wrong to me and I feel content_tag
should work in block mode with a collection somehow.
Definition of loop (Entry 1 of 3) 1a : a curving or doubling of a line so as to form a closed or partly open curve within itself through which another line can be passed or into which a hook may be hooked. b : such a fold of cord or ribbon serving as an ornament. 2a : something shaped like or suggestive of a loop.
idiom informal. to have or not have the special knowledge or power that belongs to a particular group of people: You can tell she's in the loop. She always knows about policy decisions before the rest of us.
phrase. If someone is in the loop, they are part of a group of people who make decisions about important things, or they know about these decisions. If they are out of the loop, they do not make or know about important decisions. [mainly US, informal]
(lūp), 1. A sharp curve or complete bend in a vessel, cord, or other cylindric body, forming an oval or circular ring. See also: ansa.
Try this:
def foo_list items content_tag :ul do items.collect {|item| concat(content_tag(:li, item))} end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With