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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:06:35+00:00 2026-06-04T21:06:35+00:00

I am trying to lowercase params[:user][:email] in my application but currently I’m using @user

  • 0

I am trying to lowercase params[:user][:email] in my application but currently I’m using @user = User.new(params[:user]) (which includes the email) in my def create. Is it possible to allow for mass assignment for everything except for a single item?

I know I could just not use mass assignment but I was wondering if this was possible.

  • 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-04T21:06:36+00:00Added an answer on June 4, 2026 at 9:06 pm

    Yes.

    class User
      attr_protected :email
    end
    

    Here’s how you’d use it:

    user = User.new(params[:user])
    user.email = params[:user][:email].downcase
    

    If you want to downcase the email attribute automatically though, you can simply override the email= method, which I strongly recommend:

    class User < ActiveRecord::Base
      def email=(other)
        write_attribute(:email, other.try(:downcase))                                                                                                                                                         
      end
    end
    
    Loading development environment (Rails 3.2.5)
    irb(main):001:0> User.new({:email => 'Me@you.com'})
    => #<User id: nil, email: "me@you.com", username: nil, created_at: nil, updated_at: nil>
    irb(main):002:0> User.new({:email => nil})
    => #<User id: nil, email: nil, username: nil, created_at: nil, updated_at: nil>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to merge 8 pre-sorted arrays. I'm fairly new to C, but this is
I'm trying to print all data from a csv in lowercase, but I'm not
Hi i'm trying to convert a string of lowercase letters to uppercase using regex
I'm trying to create a Textmate snippet, but have run into some difficulties. Basically,
I´m trying to upload a file which is fetched from a server. But when
I'm trying to parse command line arguments in an F# application. I'm using pattern
I am trying to create a match query which selects text from a string
I'm trying to create a textbox for a user to type in a filename.
I'm trying to create a simple animation in which the background-color slides into place.
What I'm trying to do is make a loop which prompts the user for

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.