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

  • Home
  • SEARCH
  • 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 6842117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:03:36+00:00 2026-05-27T00:03:36+00:00

I need to access multiple models from a single view. Previously, my links_controller was

  • 0

I need to access multiple models from a single view. Previously, my links_controller was only used to provide link resources sorted in different ways. Now I would like to include a partial (I’m assumning) which shows the top users sorted by score (@users = User.all.sort_by(&:score))

I’m aware that I could plug this code into every link action and access it from the view but this doesn’t seem to be the “ruby way” and I will need to access more models in the near future. This could get really dirty, are there any techniques for this situation?

Notes:

  • I see my application going in the direction of having a single format with dynamic page contents, in essence, a typical web app.
  • I’m aware of before_filter but this seems cumbersome, considering the direction that I would like the application to go in. Eventually accessing several models from any view.
  • 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-05-27T00:03:37+00:00Added an answer on May 27, 2026 at 12:03 am

    This sort of thing is best encapsulated as a helper method that’s exercised by that particular partial. For instance if this was your partial _user_listing.html.erb:

    <% users_by_score.each do |user| %>
       ...
    <% end %>
    

    Then you’d implement the users_by_score method in a helper file included by all the relevant controllers, or ApplicationHelper if it’s that prevalent:

    def users_by_score
      User.all.sort_by(&:score)
    end
    

    In other MVC systems this would be considered a sub-view with its own controller, but in Rails the best you can do is to have helper methods.

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

Sidebar

Related Questions

If I have a data/web service that multiple view models need access to what
I'm performing I/O to a single file from multiple threads. Access to this shared
How to synchronize access to data accessed from multiple threads in Qt model/view setup?
The problem is this: I have multiple competing threads (100+) that need to access
I have two different modules that need access to a single file (One will
I need to access RMI methods from a client front end. For different reasons,
I need to access a network resource on which only a given Domain Account
I need to access the bluetooth network interface from Java. All local network interfaces
I need to access a mysql database from c# code but I would prefer
We have a need to create SQLAlchemy classes to access multiple external data sources

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.