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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:34:19+00:00 2026-06-11T04:34:19+00:00

I’ve been into rails recently and I am seeing this MassAssignment Error very often

  • 0

I’ve been into rails recently and I am seeing this MassAssignment Error very often in scenarios where I want to save the child with parent_id.

To fix this everyone are suggesting to add the associated foreign key to the attr_accessbile list.

I could resolve it by doing so but am not sure what happens under the hood. Is it true that whitelisting the foreign_key would pose security problems?

Lets consider the following scenario of models:

class BusinessType < ActiveRecord ::Base
      has_one :business_form
      validates :name, :presence => true
      attr_accesible :name, :enabled  
end

class BusinessForm < ActiveRecord ::Base
      belongs_to :business_type
      validates :name, :presence => true
      validates_associated :business_type, :presence=>true
      attr_accessible :name, :enabled
end

In the above case whenever I try to save the business_form without business_type_id in attr_accessible list I would get mass assignment error. When I add it to the whitelist I am not getting any error message even the business_type select box is left empty and the form submitted.

I request anyone to shed some light in this area of rails. Please point me to any links that would explain in detail.

  • 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-11T04:34:21+00:00Added an answer on June 11, 2026 at 4:34 am

    Yes, it would pose security problems. Say someone were able to make a post to your BusinessFormController#create and they passed the “business_type_id” as part of the post. If your controller simply creates the record by doing something like this:

    def create
      BusinessForm.create(params[:business_form])
    end
    

    then it is allowing the user to specify any business type for that form. I don’t know how your site works, but that might be a problem as certain users may be allowed to create certain types of forms. The main concern with adding foreign keys to attr_accessible is that it’s allowing hackers (anyone who knows web programming at all) to associate this newly created record with any of the foreign key objects. If in this case you don’t care or it’s not restricted, then it may not matter.

    If you still want to follow what people are telling you, why not keep the attr_accessible without “business_type_id” in it, but write your action like this:

    def create
      bf = BusinessForm.new({:business_type_id => params[:business_form][:business_type_id]})
      bf.attributes=(params[:business_form].except(:business_type_id))
      bf.create
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.