I have a helper method that creates navigation links for some controllers.
def gen_associations(controllers)
content_for :leftnav do
sorted_controllers = controllers.sort
returning String.new do |content|
content << content_tag(:h3, "Associations") <<
content_tag(:ul, :class => "nav") do
sorted_controllers.collect do |c|
content_tag("li", :class => ("last" if c == sorted_controllers.last)) do
link_to(c.humanize, eval("admin_#{c}_url"))
end
end
end
end
end
end
I don't like this deeply nested structure, and the extra <<
and the end of one of the lines.
How can I rewrite it so it's not nested like that (in fewer lines) and without long lines (<80 chars)?