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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:35:04+00:00 2026-05-14T19:35:04+00:00

I have a variable called account_type passed from a rails form and need to

  • 0

I have a variable called “account_type” passed from a rails form and need to access the value in the corresponding model.

I can check if :account_type exists as a symbol, but where does the stored data come into play? Is there something I need to do in the controller?

This code gives an undefined method ‘account_type’ error.

validates_format_of :name, :with => /^[a-z0-9_]+$/i, :on => :create if account_type == 2 

If I use a symbol then it doesn’t give an error, but a symbol will never equal 2

validates_format_of :name, :with => /^[a-z0-9_]+$/i, :on => :create if :account_type == 2

It’s confusing that you can validate the format of a symbol (like :name above) when :name only seems to be a reference with nothing stored in it.

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-05-14T19:35:05+00:00Added an answer on May 14, 2026 at 7:35 pm

    Check the format for :if parameter.

    You need to pass method name (symbol) or Proc:

    validates_format_of :name, :with => /^[a-z0-9_]+$/i, :on => :create, :if  => Proc.new { |m| m.account_type == 2 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In entity framework I have an Entity 'Client' that was generated from a database.
I've got a scenario where we have a customer who has a linux hosted
Just a simple question: I have read that a class should be made static
I installed a PostScript printer driver and have setup REDMON (redmonnt.dll) for redirecting postscript
In the following code I set up a change handler on a select box
In several modern programming languages (including C++, Java, and C#), the language allows integer
I'm using a proprietary platform that reported memory usage in realtime on screen. I
Working on a web based buying and selling application with PHP MySQL where users
I am working on the multifile uploader, and want to set the upload directory

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.