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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:06:59+00:00 2026-06-01T21:06:59+00:00

In my Product model I’m trying to make a scope that doesn’t show the

  • 0

In my Product model I’m trying to make a scope that doesn’t show the current users products.

class Product < ActiveRecord::Base
  def self.not_current_users_products
    where(:user_id => current_user == nil)
  end
end

This should look at the current user and see if the products belong to him or not.

How would I do this?

  • 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-01T21:07:01+00:00Added an answer on June 1, 2026 at 9:07 pm

    While there are some hacks out there to make current_user available to your models, it isn’t by default. You could set up the method to be a little more generic, then pass in your current_user:

    def self.except_for_user(user)
      where("user_id != ?", user.id)
    end
    

    Then call it with:

    Product.except_for_user(current_user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I defined a scope in my Product model that is: class Product < ActiveRecord::Base
I have a Product model: class Product < ActiveRecord::Base belongs_to :subcategory define_index do #
I have a model class 'Market' which has many products: class Market < ActiveRecord::Base
For my form I am using my Product model: class Product < ActiveRecord::Base attr_accessible
I'm using 2 joined models class Product < ActiveRecord::Base has_and_belongs_to_many :providers end class Provider
I am using acts_as_list on my Product model, and trying to make it so
Let's say that I have a Company model and a Product model, both of
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
I've created a new Yes/No attribute for products. I've extended the Product model to
I am trying to update several products that are fed from an XML file

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.