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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:52:20+00:00 2026-06-10T17:52:20+00:00

I currently have a form where I need to remove some fields from the

  • 0

I currently have a form where I need to remove some fields from the params in the controller before it is saved (there are no columns for the fields, they are used only to populate linked selects).

The problem is this: I get a mass assignment error for the fields that should not be sent before I have a chance to remove them. I was of the understanding that the error would only fire when the controller gets to @sale = Sale.new(params[:sale]) but it seems to be occurring before that (I put line at the very start of the controller below, puts "sale params: " + params[:sale].to_s but it does not fire, only the mass assignment error occurs.

My controller create action code looks like:

def create
  puts "sale params: " + params[:sale].to_s
  params[:sale] = params[:sale].except([:vehicles_attributes])
  @sale = Sale.new(params[:sale])
  if @sale.save
    redirect_to @sale, :notice => "Successfully created address."
  else
    render :action => 'new'
  end
end

How can I ensure that the :vehicles_attributes hash is removed from params before I get the mass assignment error?

EDIT: Full error, as requested:

ActiveModel::MassAssignmentSecurity::Error in SalesController#create

Can't mass-assign protected attributes: make, model

Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"LX/uEp5o9smc3sCcjQbOXQQgaK2wihvS0OPZTdNOj6w=",
"sale"=>{
  "sale_type_id"=>"1",
  "date"=>"",
    "customer_attributes"=>{
      "customer_type_id"=>"1",
      "emails_attributes"=>{
        "0"=>{
          "value"=>""}}},
    "vehicles_attributes"=>{
       "0"=>{
         "make"=>"4",
         "model"=>"38",
         "trim_id"=>"658",
         "model_year_id"=>"12"
}}}}

Make and Model are the attributes I am trying to remove when I am doing params[:sale] = params[:sale].except([:vehicles_attributes]) (they are in the :vehicles_attributes hash, as you can see from the error).

  • 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-10T17:52:22+00:00Added an answer on June 10, 2026 at 5:52 pm

    After a LOT of investigating, it turned out that I was unable to remove the parameters from the hash before the error because the create method was being overridden by the Cancan gem (when I did load_and_authorize_resources.

    Removing this solved the problem, when using the code from Frederick Cheung.

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

Sidebar

Related Questions

I currently have form that checks if a user has unsubmitted changes when they
I currently have a datasource from a client in the form of XML, this
I currently have code similar to this for a form: $('#some-form') .submit(function() { //
I currently have a form with inputs and name attributes. I'm able to get
We currently have a form with the standard multi-select functionality of here are the
I currently have a simple form that when you click the save button will
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
I currently have a PHP form that uses AJAX to connect to MySQL and
I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
I currently have this as a search: <%= form_tag users_path, :controller => 'users', :action

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.