gpt4 book ai didi

ruby-on-rails - 如何重构这段 Rails 代码?

转载 作者:太空宇宙 更新时间:2023-11-03 17:02:41 24 4
gpt4 key购买 nike

出于好奇:

如何美化/重构这个(相当丑陋的)Rails 代码:

def section_link(name, path)    
link = link_to(name, path)
if name != controller.controller_name.titlecase
link
else
link_to(name, path, :class => 'current')
end
end

最佳答案

def section_link(name, path)
options = {}
options[:class] = 'current' if name == controller_name.titlecase
link_to name, path, options
end

关于ruby-on-rails - 如何重构这段 Rails 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12772387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com