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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:47:15+00:00 2026-05-19T21:47:15+00:00

I am using Ruby on Rails 3 and I would like to know some

  • 0

I am using Ruby on Rails 3 and I would like to know some behaviours of this code:

@user.send :attributes=, @attrib, false

That is from here.

If I have a form that return these parameters to my controller:

params[:name]
params[:surname]
params[:email]

and in the controller I use

@user.send( # Avoiding 'attr_accessible'
  :attributes=, {
  :name => params[:name],
  :surname => params[:surname] },
  false )

@user.save

it should save only ‘name’ and ‘surname’ attributes for the @user ActiveRecord. I tryed that, and it works as expected. But…

1. is it possible that a malicious user can set the email value in someway on the saving process (also if the email attribute is not considered in the “send” statement)?

2. is it right the following statement?

Calling attributes= with false doesn’t
update anything yet, it just sets the
attribute values while ignoring any
attr_accessible whitelist.

So you can just call save afterwards,
which returns the boolean value you’re
looking for.

  • 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-19T21:47:16+00:00Added an answer on May 19, 2026 at 9:47 pm

    Your code will definitely not allow a malicious user to set the email. I would recommend using the following code though, since it performs the same thing and is easier to read:

    @user.name = params[:name]
    @user.surname = params[:surname]
    @user.save
    

    Also, passing true as the second parameter to attributes= allows you to protect your attributes using attr_protected and attr_accessible. You can view the documentation here. That means your statement is correct: passing false as the second attribute ignores your mass-assignment protected attributes.

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

Sidebar

Related Questions

I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails 3 and I would like to know some
I am using Ruby on Rails 3 and I would like to know what
I am using Ruby on Rails 3 and I would like to know what
I am using Ruby on Rails 3 and I would like to know in
I am using Ruby on Rails 3 and I would like to send 'email'
I am using Ruby on Rails 3 and I would like to handle user
I am using Ruby on Rails 3 and I would like to handle properly
What is the simplest way to send mail using Ruby on Rails? Is there
I am using some nested layouts in Ruby on Rails, and in one of

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.