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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:47:21+00:00 2026-06-17T02:47:21+00:00

I am not sure why my checkboxes for a has_many through are not saving.

  • 0

I am not sure why my checkboxes for a has_many through are not saving. This is a rather complex form (An online application for a language summer program) so in addition to regular applicant information, I am collecting attributes of a LanguageBackgroundAndInterest model using a fields_for. Part of these attributes are the books that the applicant used to learn the language. The code looks like this:

    <%= f.fields_for :language_background_and_interest do |builder| %>
      <div class="field"> 
      <%= hidden_field_tag "language_background_and_interest[book_ids][]" %>
      <% Book.all.each do |book| %>
        <br><%= check_box_tag "language_background_and_interest[book_ids][]", book.id %>
        <%= book.name.humanize %>
      <% end %>
      </div>
    <% end %>

Both the language_background_and_interest and books are joined together using a has_many_through like so:

class LanguageBackgroundAndInterest < ActiveRecord::Base
  attr_accessible :book_ids

  has_many :language_background_books
  has_many :books, through: :language_background_books
end

class Book < ActiveRecord::Base
  attr_accessible :name, :publisher

  has_many :language_background_books
  has_many :language_background_and_interests, through: :language_background_books
end

# Join Table
class LanguageBackgroundBook < ActiveRecord::Base
  attr_accessible :language_background_and_interest_id, :book_id
  belongs_to :language_background_and_interest
  belongs_to :book
end

I am not sure why the books from the checkboxes don’t get assigned to the appropriate background model. Any ideas?

PS: Granted, this design is rather ambiguous (Why not make books belong to an applicant?), but I currently want to put up a prototype and I am also constrained by a dubious requirement. So I need this working.

  • 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-17T02:47:23+00:00Added an answer on June 17, 2026 at 2:47 am

    I ended up reviewing my model design and simplified it. I also switched to Simple Form to ease up working with my complex forms.

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

Sidebar

Related Questions

I'm not sure if I'm just form building impaired or not thinking about this
I am not sure how to ask this. The program I am working on
Not sure whats going on here, or what could be the integer in this
Not sure how to ask this, but i'll give it a try: I have
Not sure if this is a big deal. But wondering why when the site
Not sure if this is the correct Stack Exchange website but here goes.. A
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
Not sure if this is a security feature, an oversight, or me missing the
Not sure if this is possible: I want to use datatables to manipulate my
I'm sure this has been asked many times before but I'm not sure what

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.