Loop & output content_tags within content_tag in helper

后端 未结 5 1528
我在风中等你
我在风中等你 2020-12-23 11:45

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\', \'#\' ) ... ] )
         


        
5条回答
  •  抹茶落季
    2020-12-23 12:29

    I couldn't get that work any better.

    If you were using HAML already, you could write your helper like this:

    def foo_list(items)
      haml_tag :ul do
        items.each do |item|
          haml_tag :li, item
        end
      end
    end
    

    Usage from view:

    - foo_list(["item_one", link_to("item_two", "#"), ... ])
    

    Output would be correctly intended.

提交回复
热议问题