Learn how to clean up your code through refactoring. This episode will show you how to move code from the view into the model to remove duplication and simplify the view.
<!-- show.rhtml -->
Name: <%= @user.full_name %>
# models/user.rb
def full_name
name = first_name + " "
name += "#{middle_initial}. " unless middle_initial.nil?
name += last_name
name
end
通过重构技巧学习如何清理代码,将视图中的代码移至模型中以消除重复并简化视图。示例展示了如何在Ruby on Rails应用中实现这一点。
1944

被折叠的 条评论
为什么被折叠?



