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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:32:56+00:00 2026-05-23T07:32:56+00:00

I wanted to start using attr_accessible with my models to stop the problem with

  • 0

I wanted to start using attr_accessible with my models to stop the problem with mass assignment. I understand how it works and have researched as much as I could.

What I don’t understand is the difference between using update_attributes(params[:my_form]) or create(params[:my_form]) and setting the fields one by one? Aren’t both just as vulnerable?

What is the difference between NOT having attr_accessible and doing this…

@model_object = ModelObject.new
@model_object.create(params[:model_object_params])

And having attr_accessible and doing this…

@model_object = ModelObject.new
@model_object.field1 = params[:model_object_params][:field1]
@model_object.field2 = params[:model_object_params][:field2]
@model_object.field3 = params[:model_object_params][:field3]
@model_object.save!

Aren’t both these methods of creating the record just as vulnerable? The hacker/cracker could send a url to both these methods and both would do just the same, right?

Or does using attr_accessible and updating the fields one-by-one do something different or somehow become safer?

There’s where all these methods I’m finding of using attr_accessible don’t make any sense to me. It seems to be doing the same thing two different ways. What am I missing?

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-23T07:32:56+00:00Added an answer on May 23, 2026 at 7:32 am

    In the way you are doing it, it does not prevent “mass assignment”.

    “Mass assignment” is the term used when Rails is handling the assigning of values to attributes in a model. This is typically done in a controller, using the names and values in params.

    When you’re doing the assigning yourself, it is also “mass assignment”, in a way; but you have fine control over what to assign and what not to in this case. So, to save writing that boilerplate assignment code, Rails provides attr_accesible – same control, less code.

    To see how it is used:

    Presume that a ActivityLog model has an attribute called user_ip_address.

    Now, user_ip_address is an attribute in the model, and could be assigned by mass-assignment or by “self-rolled-mass-assignment”.

    But in both cases that is wrong — you don’t want user-supplied input to set a value for that attribute.

    Instead, you want to always find out the actual IP address of the user and assign that value (ignoring any
    value in params). So you would exclude user_ip_address from attr_accessible and instead assign it yourself.

    attr_accessible :all_attributes_except_user_ip_address
    
    @al = ActivityLog.new(params[:model_object_params])
    @al.user_ip_address = get_origin_user_ip_address
    @al.save
    

    For any information that a user should not be able to change, use attr_accessible and exclude it from the list.

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

Sidebar

Related Questions

For quite a long time I've wanted to start a pet project that will
I wanted to generate one fix view using interface builder, but the size of
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
I wanted some of those spiffy rounded corners for a web project that I'm
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
I wanted to emulate a popular flash game, Chrontron, in C++ and needed some
Just wanted to get an idea for ways (web) developers get round the short
I wanted to do something like this: <asp:Label ID=lblMyLabel onclick=lblMyLabel_Click runat=server>My Label</asp:Label> I know
just wanted to gather different ideas and perspectives as to which layer should (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.