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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:22:55+00:00 2026-05-11T17:22:55+00:00

Throughout our site there’s a common model, let’s say Video, that has a number

  • 0

Throughout our site there’s a common model, let’s say Video, that has a number of attributes like private/public/pending, downloadable, etc.

Based on the controller, action, request parameters and current user, we want to filter out particular videos from display. For instance, on the homepage we only want to show videos that are public. If there is a logged in user on the homepage we also want to show public downloadable videos.

We also want to make sure that these filters can be applied through sql queries alone, so that using Sphinx we can filter out undesired videos when a user does a search on the site.

Is this best handled through an authorization plugin, such as rails-authorization-plugin? Bottom line our goal is to prevent programmers from accidentally forgetting to filter out particular videos when they add a new action. The solution we’re looking for should be very programmatic.

Here’s a solution I’m thinking of (haven’t written any code yet)

  1. Make use of an authroization plugin or roll our own that allows setting which videos are displayed, defined at the controller or action level.

  2. Create an association extension for any model that has_many(:videos) or has_one(:video), which allows us to overload the finder for videos in the association.

  3. Overload Video.find in a similar manner to restrict what to display based on the current rules.

  • 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-11T17:22:55+00:00Added an answer on May 11, 2026 at 5:22 pm

    Your general strategy seems sound, but I’d strongly suggest you don’t override rails default finders. Instead, here’s something I’ve done in the past:

    class Video < ActiveRecord::Base
      named_scope :available_to, lambda {|user|
        if user.nil?
          :conditions => {:public_accessible => true}
        elsif user.omnipotent?
          {}
        else 
          :conditions => [%{
            videos.public_accessible = ? OR EXISTS (
              ....boring security stuff linking to users....
            )
          }, true, user.id]
        end 
      }
    end
    

    Then in video_shop.rb:

    class VideoShop < ActiveRecord::Base
      has_many :videos 
    end
    

    Finally, put it all together:

    # All videos available to a user
    Video.available_to(user)
    
    # All videos in a given shop
    video_shop.videos
    
    # All videos in a given shop available to a given user
    video_shop.videos.available_to(user)
    

    Note that these work even if user is nil.

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

Sidebar

Related Questions

No related questions found

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.