User
有许多Folder
s。要实现的Folder
的index
行动,我可以查询特定用户的文件夹中的控制器:Rails - 在视图或控制器中查询模型?
class FoldersController < ApplicationController
def index
@folders = current_user.folders
end
end
#app/views/folders/index.html.haml
- @folders.each
...
但我可以跳过控制器以及:
#app/views/folders/index.html.haml
- current_user.folders.each
...
当然前者更优雅。但它们有很大不同吗?我的意思是,他们是否有不同的表现或有时会输出不同的结果?