#10 Refactoring User Name Part 1

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


你可能感兴趣的:(java,UP)