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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:57:33+00:00 2026-06-09T17:57:33+00:00

I am working with a form having 2 checkboxes: option_one and option_two . I

  • 0

I am working with a form having 2 checkboxes: option_one and option_two.

I don’t want to allow submission of the form if option_two is checked and option_one is not.

In other words if somebody checks option_two, they must check option_one as well.

So in my MyModel I wrote :

validates :option_one, :presence => true, :if => option_two_active?, :message => "Dummy message."

Then in the MyController, I added :

def option_two_active?
    params[:option_two] == "1"
end 

But it keeps giving me the following error :

NoMethodError in MyController#index

Is my approach correct ? How can I achieve this ? Thanks in advance.

  • 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-09T17:57:34+00:00Added an answer on June 9, 2026 at 5:57 pm

    You have to specify the conditional method with a symbol:

    validates :option_one, :presence => true, :if => :option_two_active?, :message => "Dummy message."
    

    Also, you since you can’t use params from a model, you should assign that value to the model from the controller, either with create, update_attributes, or manually. If you want to persist the option_two field, then it should be a database column, else you can just create an attribute accessor:

    attribute_accessor :option_two
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting my form submission working. I'm using a preventDefault in order
I am working on a windows form project and having some problem with UserControl
I'm having a problem with a jQuery form that I'm working on at the
Having created dropdown lists using ViewBag which is working in an edit form. How
I'm having trouble understanding the workings of Javascript...I want to pass a form name
I am working on the following form for a local charity. I am having
I've got this form working, but according to my previous question it might not
I am working on having data taken from a form submit to a database,
I am working on a contact form. Now I am having a problem when
I'm having a problem similar to jQuery $.ajax Not Working in IE8 but it

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.