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
...
當然前者更優雅。但它們有很大不同嗎?我的意思是,他們是否有不同的表現或有時會輸出不同的結果?