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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:22:30+00:00 2026-05-27T06:22:30+00:00

I created a form (Form1) and a validation to go along with it. Then

  • 0

I created a form (“Form1”) and a validation to go along with it. Then I created a different form (“Form2”) for another purpose but the validation method for “Form1” is being triggered when I submit Form2

Form2 and Form1 are both being submitted to the same database, but I didn’t think the validation would apply to both of them, because attribute/method names were different in the forms

Form 1

<%= form_for(@guess) do |f| %>
  <% if @guess.errors.any? %>

<div class="field">
    <%= f.label(:math, "I think many students will fail Math") %>
    <%= f.check_box(:math) %> </br>
    </div>
<div class="field">
    <%= f.label(:french, "I think many students will fail French") %>
    <%= f.check_box(:french) %> </br>
    </div>

I do the same for 6 subjects. Students are required to select 3 subjects that might create fails..

Validation for Form1 in model Guess.rb

validates_inclusion_of :possible_assessment_failures, :in => 1..3, :message => "You must check off 1,2 or 3 different assessments for question 1"
...
def possible_assessment_failures
  [math, french, english, science, history, geography].select{|x| x }.count
end

Comment: I assumed that this validation got triggered because the methods in the form (:french, :math etc) were in the array [math, french…] in the validation…I’m guessing that’s wrong

—

Form2

In the controller….
@teacher = Guess.new

in the view…

<div class="field">
    <%= f.label(:MrSmith, "MrSmith") %>
    <%= f.select:MrSmith, 1..6 %> </br>
    </div>

So why is the validation for form1 getting called when I submit form2?

As mentioned, I thought the validation got called for form1 because the methods in the array in the validation (i.e. the names of the subjects

[math, french, english, science, history, geography].select{|x| x }.count

were named in the form

<%= f.check_box(:math) %>

so if my Form2 has different attributes (like teacher’s names

<%= f.select:MrSmith, 1..6 %>

I don’t understand why that would trigger a validation with the names of subjects (math, french etc) in it?

I’m assuming that’s totally wrong thinking on my part. So what triggers the validation and how do I get it not to apply on form2?

  • 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-27T06:22:31+00:00Added an answer on May 27, 2026 at 6:22 am

    All of the validations in Guess.rb are called whenever the guess model is saved (by default, you can disable them with save(:validate => false)).

    It’s not generally a good idea to only apply some validations when saving a model since you’ll lose the guarantee that your database is consistent with all of your validations.

    If you really want to do it, you could create a new attribute and only run the validation if that attribute is true, see this answer https://stackoverflow.com/a/3956701/625365

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

Sidebar

Related Questions

I have created an form validation using ajax/php. Each text box is validated using
I created a form that overlays on top of another form in an alpha
I created a form and wrote all the JQuery for it -- form validation
I have a created a zend form, works fine along with validations. Is there
I have a long form to test, so I created a CompleteForm() helper method
i have created this regular expression for my form validation of password feild /^[[A-Za-z0-9]+[A-Za-z0-9,
I created a form with a label, textbox and a button. In the form
I created a form application with 1 button and 1 text box to see
I created a form using Swing in Java. In the form I have used
Once I created a form builder where user could select any number of fields

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.