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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:39:18+00:00 2026-05-26T22:39:18+00:00

I have encountered a problem in my application and realized that I could fix

  • 0

I have encountered a problem in my application and realized that I could fix it by setting :without_protection => true when creating a model, e.g.:

Model.new(params[:model], :without_protection => true). 

What exactly is rails protecting the models from? Thanks!

  • 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-26T22:39:19+00:00Added an answer on May 26, 2026 at 10:39 pm

    It’s protection against unintended mass assignment.

    The problem with the code you shown is that users can alter the form and change attributes you don’t want them to change, like hashed passwords on users or a published status on posts.

    You can use attr_protected and attr_accessible on models to protect attributes on your models to be overridden. When an attribute is protected than the value from params will be ignored (a notice will appear in your log).

    class Model < ActiveRecord::Base
      attr_accessible :one, :two
    end
    

    Before Rails 3.1, that was it. There was no way to configure it afterwards. Now, with Rails 3.1, you can assign roles:

    class Model < ActiveRecord::Base
      attr_accessible :one, :two, :as => :admin
      attr_accessible :one, :as => :regular_user
    end
    

    And specify it when doing mass updates (new or update_attributes):

    Model.new(params[:model], :as => :regular_user)
    

    Using :without_protection, will make every attribute free to be mass assigned and should be used VERY sparingly. Never use when you’re passing in user data. You might use it in db/seeds.rb for example.

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

Sidebar

Related Questions

I have encountered a problem in my application. I have two forms, one that
I have encountered a problem that I have not come accross yet when setting
I recently encountered an odd problem with RSACryptoServiceProvider.VerifyHash . I have a web application
I have encountered a most annoying problem that occurs on the PWD variable when
I am beginner in C# programming. I have encountered small problem during building application
I am making a multiple form based application and have encountered a problem with
I am developing a silverlight navigation application and have encountered the following problem. I
I am relatively new to JMS and have encountered a weird problem implementing my
Currently porting an application to Windows Phone 7 I've encountered a problem that should
I have encountered a problem twice now whereby a producer thread produces N work

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.