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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:58:17+00:00 2026-06-11T12:58:17+00:00

In Rails 3, we can define the accessible attributes: attr_accessible :rating, :review In this

  • 0

In Rails 3, we can define the accessible attributes:

attr_accessible :rating, :review

In this model, there is additional user_id which is protected to prevent forgery/hacking. This value is assigned in the controller:

@review.user_id = current_user.id

If I use Firebug to manually include the user_id, it will be part of the params[:review], but of course since user_id is not defined in the attr_accessible, it wouldn’t get saved into the database. Such case is rather secure.

Question 1

I read in Rails 3 In Action book, Yehuda Katz included .delete method to delete unauthorized params before further action is performed: params[:review].delete(:user_id). Should I include this as well to further secure my app, or just ignore this step?

Question 2

If I should include the method above, I would like to have something like .delete_all_except to just strip it to the allowed attributes in the params. How do I do that?

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-06-11T12:58:19+00:00Added an answer on June 11, 2026 at 12:58 pm

    If enabled, Rails 3.2 will through an exception if additional mass-assignment params are sent to the model

    config/application.rb

    config.active_record.whitelist_attributes = true
    

    Rather than deleting out parameters you don’t want, I recommend only accepting parameters you do want:

    @user.update_attributes params[:user].slice(:rating, :review)
    

    This will only return the user params you allow.

    note: in Rails 4 (coming soonish), this behavior is implemented with a DSL named strong-parameters. You can install this gem in Rails 3.2 to implement now:

    @user.update_attributes params.require(:user).permit(:rating, :review)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Rails , where should I define the variable which can be recognized by
I'm getting this error while doing rake:seed. can't mass-assign protected attributes I know that
How can I clean this up using rails 3 features? I have a post
Can anyone suggest me how I can define a custom model name. When I
How can I define the environment when restarting a Rails app from the command
I just had a general question about Ruby on Rails and the attr_accessible attributes
There is a mass assignment defined in sys_log model in our rails 3.1.4 app:
How would I create the following scenario that rails can provide for carrierwave, using
Can rails handle creating a view without a controller? For example, let say I
A single Rails command can make lots of changes in an app - creating

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.