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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:27+00:00 2026-05-29T10:13:27+00:00

I’m trying to add has_many_through relationship through a form nested in a parent model.

  • 0

I’m trying to add has_many_through relationship through a form nested in a parent model. I can’t figure out if this is possible?

The nested form works ok without the checkboxes. And the checkboxes work fine when they’re outside the nested form.

= semantic_form_for @raduser do |f|
  %ul       
    %li
      = f.text_field :expiration, :placeholder => 'Expiration Date', :id => 'expiration_date'
    - f.fields_for :radcheck do |builder|
      = builder.text_field :username, :placeholder => 'Stuff'
      -Radgroup.all.each do |group|
        %li
          = check_box_tag 'radcheck[radgroup_ids]', group.id, @radcheck.radgroup_ids.include?(group.id)
          = group.groupname          

    %li
      = f.submit

This throws an error:

 undefined method `radgroup_ids' for #<ActiveRecord::Relation:0x007faaa24c2468>

I’ve got the models set up fine I think as all values save perfectly without the checkboxes

— EDIT ADDED MODELS —

Radusers have many Radcheck (singular due to legacy db). Radcheck has many radgroups through radusergroup.

class Raduser < ActiveRecord::Base

  has_many :radcheck, :dependent => :destroy
  accepts_nested_attributes_for :radcheck, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true   

end

class Radcheck < ActiveRecord::Base
  self.table_name = 'radcheck'

  attr_accessible :attribute_name, :username, :value, :op, :radgroupcheck_id, :radcheck_serial, :radgroup_ids

  belongs_to :raduser

  has_many :radusergroup, :dependent => :destroy
  has_many :radgroup, :through => :radusergroup

end

class Radgroup < ActiveRecord::Base
  self.table_name = 'radgroup'

  has_many :radusergroup, :dependent => :destroy
  has_many :radcheck, :through => :radusergroup

end


class Radusergroup < ActiveRecord::Base

belongs_to :radcheck
belongs_to :radgroup

end

— UPDATE TWO —

 def new
  @radcheck = Radcheck.new
  ...      
 end

 def create
  @radcheck = Radcheck.new(params[:radcheck])
  ...
 end

— UPDATE 3 —

My db currently looks like this:

 +----------------+-----------------------+----------+------+
 | radcheck_id    | radgroup_id           | priority | id   |
 +----------------+-----------------------+----------+------+
 | 8              | 3                     |        1 |    1 |
 | 4              | 9                     |        0 |    2 |
 | 22             | 4                     |        1 |    3 |
 | 2              | 6                     |        1 |    4 |

I have the solution suggested below working.

What I was hoping to do was insert the radcheck_username and radgroup_groupname into the db, not the radcheck_id:

+----------------+-----------------------+----------+------+
| ...username    | --groupname           | priority | id   |
+----------------+-----------------------+----------+------+
| user123344     | group88888            |        1 |    1 |
| shushQb        | 30-minutes            |        0 |    2 |
| forty          | gigiig                |        1 |    3 |
| snang          | ps-staff              |        1 |    4 |

Is this possible?

  • 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-29T10:13:27+00:00Added an answer on May 29, 2026 at 10:13 am

    The problem appears to be that you’re trying to access Radcheck’s various Radgroups through a method that isn’t defined yet. I can see a couple of solutions to this. One would be to add the missing radgroup_ids method to your model. Alternatively, I think you could call include? on Radchecks radgroups relation.

    Solution A

    Within your Radcheck class, define:

    def radgroup_ids
      radgroups.map(&:id)
    end
    

    Solution B

    Make a minor change to the way you’re checking for included Radgroups

    @radcheck.radgroups.include?(group)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.