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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:12:28+00:00 2026-06-07T22:12:28+00:00

Using Ruby 1.9.3 and ActiveRecord 3.2.6. I’m having an issue when trying to compare

  • 0

Using Ruby 1.9.3 and ActiveRecord 3.2.6.

I’m having an issue when trying to compare an ActiveRecord Object that has attr_accessible :property set on it, that is contained in an Array of associated Objects using include?(object).

These are my 2 ActiveRecord models, Account and Role.

Account:

class Account < ActiveRecord::Base

  # Associations
  #
  has_many :role_assignments, :dependent => :destroy
  has_many :roles, :through => :role_assignments
end

Role:

class Role < ActiveRecord::Base

  attr_accessible :title

  # Associations
  #
  has_many :role_assignments, :dependent => :destroy
  has_many :accounts, :through => :role_assignments
end

If I then create a couple of Roles (say “Admin” and “Editor”) and assign the “Admin” one to an Account, I would assume this would work:

role = Role.find_by_title("Admin")
account = Account.first # => The Account we assigned the "Admin" role to

account.roles.include?(role) # => Should be true but returns false

But this actually returns false!

If I remove the ‘attr_accessible :title’ from the Role model and repeat the above then it does return true.

So I guess my question is… why would attr_accessible cause this particular issue? or is it a case that I have to do my check to see if role does exist in account.roles a different way?

  • 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-07T22:12:30+00:00Added an answer on June 7, 2026 at 10:12 pm

    You could try that

    account.role_ids.include?(role.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails 3.0.7 and I am trying to set correctly
I'm using Ruby on Rails/ActiveRecord and am having trouble with an ActiveRecord#find call. I'm
It seems that ActiveRecord and Ruby's Time object doesn't play nice with times that
I'm using Ruby 1.8.6 and have a class ( not an ActiveRecord class) that
I am looking at using Ruby on Rails for a storefront that has to
Using Ruby, I'm trying to parse some documentation in which I need to split
Using Ruby on Rails. I'm trying to sort a query by number (saved as
Using Ruby (newb) and Regex, I'm trying to parse the street number from the
I'm running ruby on Mac OSX 10.6.4, using Ruby 1.8 and activerecord 2.3.8. I'm
I'm using Ruby 1.8.7 and Rails 2.3.8 I have two ActiveRecord Models, A and

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.