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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:26:52+00:00 2026-05-28T07:26:52+00:00

I have two sections in a form, and I have a button that toggles

  • 0

I have two sections in a form, and I have a button that toggles their visibility. Is there a way to restrict the submit button from sending parameters from the hidden one? It’s unfortunately creating courses without names or numbers, and it is not selecting an existing course if I use the collection_select.

projects/new.html.haml

= form_for [@user, @project] do |f|

  # This part of the form is mostly shown to the user, but is failing to work correctly
  = f.collection_select :course_id, @courses, :id, :name, { prompt: true }

  # This part of the form is typically hidden, javascript reveals it.
  .hidden
    = f.fields_for :course do |builder|
      = builder.text_field :name, class: 'large', placeholder: 'Ex: Calculus I'
      = builder.label :number, 'Number'
      = builder.text_field :number, class: 'new_project_course_number', placeholder: 'Ex: MATH-101'
      = builder.hidden_field :user_id, value: current_user.id

project.rb

belongs_to :user
belongs_to :course

attr_accessible :course_id, :course_attributes
accepts_nested_attributes_for :course

course.rb

belongs_to :user
has_many :projects

user.rb

has_many :projects
has_many :courses

Please let me know if I am leaving off any vital information accidentally.

  • 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-28T07:26:52+00:00Added an answer on May 28, 2026 at 7:26 am

    I think you might be looking for reject_if param for your nested attribute set.
    For example:

    accepts_nested_attributes_for : course, :reject_if => proc { |attributes| 
      attributes['name'].blank? 
    }
    

    Or something like this. It allows you leave submitted form as is it, but only created nested course object, when name is preset (in your case, there is some placeholder, so you might use another check here)

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

Sidebar

Related Questions

We have two images with transparent sections that each have a map and separately
Ok, so I have several sections to a webpage that I am making. There's
So I have a fairly large form with two different sections. Both sections start
I have divided form in to two sections: sec1 and sec2 . Each section
I am working on a form with a two different sections. Both sections have
I have two sections(primary and secondary) in a form with several textboxes which display
I have two sections on my PHP form. One section allows to enter Customer
I have a website that asks numerous users to fill out a form. There
I have a UITableView with two sections: free and paid. Each section has a
I have two shapes which are cross sections of a channel. I want to

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.