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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:55:51+00:00 2026-06-07T10:55:51+00:00

Based on a previous Q&A on StackOverlfow, I added the following to application.rb: config.active_record.whitelist_attributes

  • 0

Based on a previous Q&A on StackOverlfow, I added the following to application.rb:

 config.active_record.whitelist_attributes = false

as I was getting errors of the type Can’t mass-assign protected attributes

After I did that, it seemed as if everything was working fine. I am now getting that same error, but it’s a false negative. Note that even though I am getting an error, the column is actually updated.

Here’s the debugger output:

Started PUT "/categories/5" for 127.0.0.1 at 2012-07-09 11:26:40 -0700
Processing by CategoriesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"SifcfX29c+mGRIJXvUWGnZ8mBelMm4uZloYsoO317SY=", "admin_selections"=>{"admin1"=>"56", "admin2"=>"55", "admin3"=>"", "admin4"=>"", "admin5"=>"", "admin6"=>"", "admin7"=>"", "admin8"=>""}, "category"=>{"update_admins_field"=>"1"}, "commit"=>"Update Category", "id"=>"5"}
  Category Load (0.2ms)  SELECT `categories`.* FROM `categories` WHERE `categories`.`id` = 5 LIMIT 1
   (0.1ms)  BEGIN
   (0.2ms)  UPDATE `categories` SET `admins` = '[\"56\",\"55\",\"\"]', `updated_at` = '2012-07-09 18:26:40' WHERE `categories`.`id` = 5
   (1.3ms)  COMMIT
   (0.1ms)  BEGIN
   (0.1ms)  ROLLBACK
Completed 500 Internal Server Error in 5ms

ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: utf8, _method, authenticity_token, category, commit, action, controller, id):
  app/controllers/categories_controller.rb:74:in `block in update'
  app/controllers/categories_controller.rb:62:in `update'

It seems as if the MySQL code is properly generated, but then there’s a rollback and 500 error.

Here’s the relevant code from categories_controller.rb:

def update
  @category = Category.find(params[:id])
  respond_to do |format| #this is line 62
    if params[:category][:update_admins_field]
      params['admins'] = return_admins_json (params)
      if @category.update_attribute(:admins,params['admins'])
        format.html { redirect_to @category, notice: 'Category was successfully updated.' } #line 66
        format.json { head :no_content }
      end
    else
      format.html { redirect_to @category, notice: 'Category was not successfully updated.' }
      format.json { head :no_content }
    end

    if @category.update_attributes(params)  #line 74
      format.html { redirect_to @category, notice: 'Category was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @category.errors, status: :unprocessable_entity }
    end
  end
end  

Why is it getting to line 74? should’t the user have been redirected at line 66? Why am I also getting an error when the update takes place?

  • 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-07T10:55:54+00:00Added an answer on June 7, 2026 at 10:55 am

    You should set whitelist_attributes to true, and use attr_accessible in each model for security reasons. Here is information on that:

    http://guides.rubyonrails.org/security.html#mass-assignment

    Also, read Niiru’s commment above.

    Edit:

    In your control flow, I think its not doing what you want. If it gets to line 74, it probably passed the first if conditional

    if params[:category][:update_admins_field]
    

    And then failed the second if

    if @category.update_attribute(:admins,params['admins'])
    

    And then exited that if/else/end and continued to line 74 as no return had been called yet. To fix this, I think you want something like this:

    if admin category
       if update admin
          return success
       else
          return failure
       end
    else
       if update normal
          return success
       else
          return failure
       end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on my previous question here and here , I found that I can
In previous versions of Xcode creating a window-based, universal application would populate the project
I am trying to call a method that requires some parameters based on previous
Based on a previous question and with a lot of help from Damir Sudarevic
This question is based on my previous question which I got a working answer
I looked at previous post based on this but they do not relate. I
I have a non ode function that calculates based on the previous time step
I have a problem with populating an autocomplete list based on a previous input.
compliment of the day. Based on the previous feedback received, After creating a Ticket
Is there a way to get the previous item in a list , based

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.