哪个是最佳实践并给我更好的表现?
例如:
我有包含 5 条记录的状态表,每条记录都需要存储在单独的变量中。
方法1:
@new_status = Status.find_by_status("NEW")
@inprocess_status = Status.find_by_status("InProcess")
@completed_status = Status.find_by_status("Completed")
@occupied_status = Status.find_by_status("Occupied")
@success_status = Status.find_by_status("Success")
方法2:
statuses = Status.all
@new_status = statuses.find {|status| status.status == "NEW"}
@inprocess_status = statuses.find {|status| status.status == "InProcess"}
@completed_status = statuses.find {|status| status.status == "Completed"}
@occupied_status = statuses.find {|status| status.status == "Occupied"}
@success_status = statuses.find {|status| status.status == "Success"}
还是有什么好办法?