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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:16:13+00:00 2026-05-12T23:16:13+00:00

Once again, I have my form_for for my Order model, which has_many :services, :through

  • 0

Once again, I have my form_for for my Order model, which has_many :services, :through => :requests. Here’s the layout of how I have my relationships mapped:

 __________                               _________
| Customer |                             | Utility |
 ----------                               ---------
   ||   ^                                     /\
   ||   |                                     ||
   \/   |                                     /\
   _______           _________             _________
  | Order | <=====< | Request |  >=====>  | Service | 
   -------           ---------             ---------
                                              \/
                                              ||
                                              \/
                                           _________  
                                          | Company |
                                           ---------

Where:

--->                    = belongs_to
===>                    = has_many
<==< join model >==>    = has_many, :through

On my Order form, I want to have an array of checkboxes that represent the services available, such that even though the checkboxes are labelled by the Company and categorized by Utility, the Order ends up with the Service association when the order is complete (because that’s really what the customer is ordering: a Company to provide a Utility, which is a Service).

How do I accomplish this in my form?


form view:

- form_for @order do |order_form| 
  -# order form inputs, etc.
  - order_form.fields_for :customer do |customer_form| 
    -# customer form inputs
  - order_form.fields_for :services do |services_form| 
    %dl
      - @services.each do |service_name, services| 
        %dt= service_name
        - services.each do |service_item| 
          %dd
            =# check_box ??????????
            =# label ??????????, Company.find(service_item.company_id).name
  %p= order_form.submit 'Create Order'

Where:

@services = Service.all.to_set.classify { |service_item| Utility.find(service_item.utility_id).name }
  • 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-12T23:16:14+00:00Added an answer on May 12, 2026 at 11:16 pm

    There is a Railscast on HABTM checkboxes — it’s an oldie but goodie. I’m pretty sure it should still work even with a join model.

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

Sidebar

Related Questions

I need your expertise once again. I have a java class that searches a
Once again a very beginner-ish question, but here I go: I would like to
I have a login.jsp page which contains a login form. Once logged in the
Once again with the charset issues when talking to DB's :) I have two
I am once again looking for some help. I have found this stopwords script
Once again one of those: Is there an easier built-in way of doing things
Once I have all the files I require in a particular folder, I would
I have a number of rather large binary files (fixed length records, the layout
I have an iPhone application in which a number of domain objects are populated
I have a simple form (textbox, submit button) which is wrapped in an update

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.