Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:56+00:00 2026-06-09T17:46:56+00:00

The User has many Folder s. To implement the index action of Folder ,

  • 0

The User has many Folders. To implement the index action of Folder, I can query the folders of specific user in controller:

class FoldersController < ApplicationController
  def index
    @folders = current_user.folders
  end
end

#app/views/folders/index.html.haml
- @folders.each
...

But I can skip the controller as well:

#app/views/folders/index.html.haml
- current_user.folders.each
...

Of course the former is much more elegant. But are they substantially different? I mean, whether they have different performances or output different results sometimes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:46:57+00:00Added an answer on June 9, 2026 at 5:46 pm

    It will probably take the same time, but you should not have logic in your views.

    You should do it in your controller as you stated in your first of two examples. The folder view display folders, it doesn’t have to know that it is the current user’s folders.

    That way, you can do an admin action where you would retrieve let say all the folders and pass it to the same view in the variable “folders”. The view doesn’t care whose folder it just represents whatever folder list you pass to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

User has many Tracks, through Favorite. Favorite has some extra per-user meta-data about the
Let's say I have a schema where User has many Alerts (many to many).
Let's say a User has many Document s, and a single Document they're currently
In my application an User has many Projects . I want to create a
Let's say User has many projects (projects created by user) User has many memberships
So a user has many colleges (that they have attended), and a college belongs
My model: class User has_many :items end class Item belongs_to :user def self.with_color(color, is_loaded)
I have a many-to-many relationship like this: A user has_many organizations through affiliations and
Kind of a ruby-noob active record query question: Magazine has_many :subscriptions User has_many :subscriptions
I am developing a social networking site. It has functionality like user registration, people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.