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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:48:52+00:00 2026-05-31T10:48:52+00:00

A User has_one Account . When setting up attr_accessible on the User model is

  • 0

A User has_one Account. When setting up attr_accessible on the User model is it better to protect :account, :account_id or both?

attr_accessible :account

or

attr_accessible :account_id

or

attr_accessible :account, :account_id

I feel like both is the way to go (as it’s more secure) even though it feel less DRY.

Update to give more background

Just to give a bit more background on why I’m asking. I, like most ppl, saw what happened to Github so we’re going through our app and locking it down a little tighter.

In the process of doing this I found tests in which we pass in account

User.create account: account

and where we passed in account_id:

User.create account_id: account.id

My options were to either change them all to be consistant or change attr_accessible to allow either. I decided to change them all to be consistant. But this got me worried that we were perhaps using both methods throughout our app and I might break our app by only allowing one or the other.

I did misspeak when I said using both is more secure. It was a long day.

  • 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-31T10:48:53+00:00Added an answer on May 31, 2026 at 10:48 am

    There’s no right answer for this one, though it does depend on how you intend to update this user. attr_accessible :account will allow you to mass-assign the account directly like this:

    user.update_attributes(:account => account)
    

    Helpful if you already have an account object that you want to associate to the user along with a lot of other attributes. On the other hand, attr_accessible :account_id would be more appropriate if you were assigning the account’s ID, as from a dropdown or some other form element:

    user.update_attributes(params[:user]) # params[:user][:account_id] is a part of this hash
    

    This latter case is generally considered more dangerous and was part of the problem with Github’s recent security issue: that you can post any account_id you like, including an account that doesn’t belong to you, and your user will be assigned to it.

    So overall I would go for the former and do a look-up to ensure the account is one that you expect, but as I said at the beginning, you can go either way on this one depending on how you intend to use it.

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

Sidebar

Related Questions

I have an Account model with the following : has_one :primary_user, :class_name => User,
I have a User and Account models with has_one association and nested attributes. My
model: User has_one :beta_invite before_save :beta_code_must_exist def beta_code_must_exist if beta_invite_id == beta_invite.find_by_name(beta_invite.id) user else
I have a User.rb model and a Donation.rb model. User.rb has_one :donation , and
I am mapping 2 models: User Account class Account has_many :users class User has_one
I have following tables : users accounts ( user has_one account ) pictures (
Now i'm using this code: User has_one User_extra User => :username, :email, :crypted_password, :salt,
I have User and Teacher models. Teacher belongs_to User and User has_one Teacher. Also
I've got into trouble with nested attributes. Here is my Account model : class
I've got a User model with three fields, :email, :display_name and :handle. Handle is

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.