我有一個幫助器的方法,爲一些控制器創建導航鏈接。如何使這個紅寶石方法不那麼醜(嵌套)
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
我不喜歡這樣的深度嵌套的結構,而額外<<
和線之一的結束。
我怎樣才能重寫它,所以它沒有像這樣嵌套(更少的行)和沒有長行(< 80個字符)?