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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:51:33+00:00 2026-05-12T19:51:33+00:00

For conditional validation in Rails, I can do this: mailed_or_faxed_agenda = Proc.new { |me|

  • 0

For conditional validation in Rails, I can do this:

mailed_or_faxed_agenda = Proc.new { |me| me[:agenda_mailed_faxed] }
validates_presence_of :agenda, :if=>!mailed_or_faxed_agenda

but I don’t know how to parameterize the Proc. I would love to use if=>blah(name) but I cannot figure out how to it. Any ideas?

Note: In these ifs one can also use the name of a method, but as a symbol. I can’t imagine how to pass parameters to that.

  • 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-12T19:51:33+00:00Added an answer on May 12, 2026 at 7:51 pm

    By “parameterize the Proc”, do you mean currying?

    Or just this?

    my_proc = Proc.new { |chunky| do stuff to 'chunky' here }
    
    my_proc.call("bacon") # "bacon" is "chunky" in the above proc
    

    The second problem (sending params to a method), you can do something like this:

    validates_presence_of :some_column_name
      :if => Proc.new { |model_instance| model_instance.send(:some_method, arg1, arg2, arg3) }
    

    Update:

    The above can be simplified if you don’t want to parameterize the method that is called. The following is equivalent to passing a literal symbol to send:

    validates_presence_of :some_column_name
      :if => Proc.new { |model_instance| model_instance.some_method(arg1, arg2, arg3) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create conditional comments in XSLT. But when I use this: <!--
I have some conditional formatting styles. I don't want to keep creating new rules
I need to do conditional validation of models in Rails dependant on one of
I am fairly new to WPF but have spent time researching WPF validation, and
How should I test a validation with a conditional like this: validates :age, :numericality
I have the standard 'RequiredIf' attribute for some Conditional-Validation. My form and Model are
Why can't the conditional operator be used as a statement? I would like to
I have this conditional in a perl script: if ($lnFea =~ m/^(\d+) qid\:([^\s]+).*?\#docid =
Just wondering if there is a way to do a conditional callback in Rails.
is there any possibility to perform conditional validation in authlogic's model User, that uses

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.