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 8035255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:15:35+00:00 2026-06-05T02:15:35+00:00

I have a Repository model as follows: class Repository < ActiveRecord::Base belongs_to :user has_many

  • 0

I have a Repository model as follows:

class Repository < ActiveRecord::Base

  belongs_to :user
  has_many :members, :class_name => :users
  has_many :datum

end

It has a private boolean attribute, that indicates if it’s a public repository, i.e., visible for everyone. Or if it’s a private repository and only visible to his members.

What is the best way to retrieve only repositories users are allowed to see?

The logic is: if it’s public, just retrieve it. If it’s private, check if the user is on member list.

I believe I just need to create a method to check this on Repository controller, and use it to verify if user has access to it. But I can’t figure out the best way to do it!

  • 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-05T02:15:37+00:00Added an answer on June 5, 2026 at 2:15 am

    Easy way is to use authorization library. I use CanCan in all my projects.

    You can declare access right in a clean readable way.

    can :read, Project, :active => true, :user_id => user.id
    

    And then later check authorization. This line displays link only if current_user has access to the project.

    <%= link_to 'A project', @project if can? :read, @project %>
    

    For more information read cancan’s wiki.

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

Sidebar

Related Questions

I have Doctrine 2.1 entity: /** * @Entity(repositoryClass=Varlab\Model\Repository\UserRepository) * @Table(name=user) */ class User {
Say I have two separate classes, A and B. I also have Repository class
I have a repository Class which takes in a ObjectContext called TestDB. I when
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {
I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
Basically I have a Repository that controls access to my EF model. It creates
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I
Reverse engineering source code into a VS 2010 UML class model? I have a
I have repository on GitHub to which I commit regularly from my local computer.
I'm using Visual SVN on my Windows Box. I have Repository Application , which

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.