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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:59:28+00:00 2026-06-14T22:59:28+00:00

I think this question is so simple, that I am at a loss for

  • 0

I think this question is so simple, that I am at a loss for how to google it.

In RoR, if I have a protected attribute like :premium or :admin, and I only want to change it if a User does something specific (signs up for premium account or something as simple as provides a phone number), how would I do that? It should only change if certain conditions are met, but I don’t want someone to be able to fake those conditions.

I understand that things like “premimum” or “admin”, I want to avoid through mass assignment. So how do you change it if a user fills out a certain form?

Feel free to direct me to any useful links, I just cannot figure out how to word this, but I think it’s a simple solution.

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

    Read about Mass Assignment

    You can create roles

    attr_accessible :first_name, :last_name                            # default role
    attr_accessible :first_name, :last_name, :premium, :as => :special # 'special' role
    

    When calling .update_attributes(params) on this model, it will use the default role; if :premium is found in params, it will throw an error.

    In the POST method for your special form, you’d specify the :special role for the update_attributes like .update_attributes(params, :special), directing the update_attributes to use the :special role which allows the mass assignment of the :premium attribute.

    You can conditionally pass the role name based on some property in params, like the phone number having a value like you mentioned

    @the_model.update_attributes(params, params[:phone_no].present? ? :special : :default)
    

    If these conditions are more complex, you might consider adding them as a class method to the model

    def self.special_role?(params)
      # fancy conditions here, returning true/false
    end
    

    and then the update_attributes might look like

    @the_model.update_attributes(params, TheModel.special_role?(params) ? :special : :default)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is simple question but google only gives me select and count
I think this is a simple and a silly question. I have included a
I'm sorry that I put this question because I think that is simple but
I think this is a simple question, but I can not find the answer
I think this is a simple question. How do I disable copy from a
i think this is a simple question but I've searched around and can't seem
I think this is a pretty simple question. How do you an apache rewrite
[see later answer for more] I think this is just a simple rails question,
I'm hoping this question has a very simple answer. I can think of ways
I am sure there is a very simple answer to this question, I think

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.