JRL*_*JRL 1 ruby coding-style nested ruby-on-rails
我有一个帮助方法,为一些控制器创建导航链接.
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
Run Code Online (Sandbox Code Playgroud)
我不喜欢这种深层嵌套的结构,以及<<其中一条线的额外和结束.
我怎样才能重写它所以它不是那样嵌套(在更少的行中)和没有长行(<80个字符)?
| 归档时间: |
|
| 查看次数: |
540 次 |
| 最近记录: |