从内到外构建:
def gen_associations(controllers)
sorted_controllers = controllers.sort
list_items =
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
list = content_tag(:ul, list_items.join, :class => "nav")
content_for :leftnav do
content_tag(:h3, "Associations") << list
end
end
我可能会把
content_for
对视图或局部
gen_associations()
返回
list
.
...
<% content_for :leftnav do %>
<h3>Associations</h3>
<%= gen_associations(@controllers) %>
<% end %>
...