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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:38+00:00 2026-05-30T17:25:38+00:00

I am very new to Ruby (2-3 days) and am using it on an

  • 0

I am very new to Ruby (2-3 days) and am using it on an existing DB. I have a user table (previously built in Joomla) and have managed to get it working (well, logging in and out), but i need to constrain another model i.e. ‘Leads’ to the user that is logged in.

I have been able to get ALL the current ‘leads’ output and using CRUD operations, but i would like to know how to limit the data based on the user that is logged in.

The ‘leads’ model was generated using scaffolding and the ‘set_table_name’ and ‘set_primary_key’ attributes have been overridden. I have also added

belongs_to :user,
:class_name => "user",
:foreign_key => "leadid"

to the model.

The ‘user’ model is as follows

class User < ActiveRecord::Base
 # Include default devise modules. Others available are:
 # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and      :omniauthable
`establish_connection :web_development
 set_table_name "users"
 set_primary_key "id"

 has_many :leads,
       :class_name => "Lead",
       :foreign_key => "LeadID"

devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :validatable

 # Setup accessible (or protected) attributes for your model
 attr_accessible :email, :password, :password_confirmation, :remember_me

   alias :devise_valid_password? :valid_password?
   def valid_password?(password)
     return true (temp to bypass the password)
   end 
 end

Many thanks
Rudy

  • 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-30T17:25:39+00:00Added an answer on May 30, 2026 at 5:25 pm

    Devise provides an accessor to the currently logged in user with current_user. Since it looks like you have the relationship set up correctly, if you want to show only the leads for the logged in user in your index action of the controller you just need this:

    def index
        @leads = current_user.leads
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a very simple blog application using Ruby on Rails. New to
I'm very new to ruby and I'm trying to write a web application using
I'm very new to Ruby on Rails, and have been getting the following error
I'm very new to ruby & Sinatra and I have a basic question: The
I'm very new to Ruby, and currently running through the Ruby Koans to get
I'm very new to Rails (and Ruby), and am having trouble installing and using
I am very new to ruby / rails and have an issue that I
I am very new to ruby on rails.. working on my first project... am
I am new to ruby and started using it for the last few days,
very new to Ruby, I've got the following situation. I have a file with

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.