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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:36:45+00:00 2026-06-14T01:36:45+00:00

I have 3x models: class Heuristic < ActiveRecord::Base has_many :footnotes has_many :references, :through =>

  • 0

I have 3x models:

class Heuristic < ActiveRecord::Base
  has_many :footnotes
  has_many :references, :through => :footnotes
end

class Reference < ActiveRecord::Base
  has_many :footnotes
  has_many :heuristics, :through => :footnotes
end

class Footnote < ActiveRecord::Base
  belongs_to :reference
  belongs_to :heuristic
end

A join table:

class CreateFootnotes < ActiveRecord::Migration
  def change
    create_table :footnotes do |t|
      t.integer :heuristic_id
      t.integer :reference_id
      t.timestamps
    end
  end
end

A form called from the new reference view:

= form_for @reference do |f|
  .field
    = hidden_field_tag "reference[heuristic_ids][]", nil
    - @heuristics.each do |heuristic|
      = label_tag dom_id(heuristic), heuristic.description
      = check_box_tag "reference[heuristic_ids][]", heuristic.id, @reference.heuristics.include?(heuristic), id: dom_id(heuristic)
  .actions
    = f.submit 'Save'

A references controller:

  def new
    @reference = Reference.new
    @heuristics = Heuristic.all
    respond_to do |format|
      format.html # new.html.erb
    end
  end

  def create
    @reference = Reference.new(params[:reference])
    respond_to do |format|
      if @reference.save
        format.html { redirect_to references_path, notice: 'Reference was successfully created.' }
      else
        format.html { render action: "new" }
      end
    end
  end

When you go to the new reference view, select a heuristic and click Save, I expect this to associate the selected heuristic with the reference, but when you drop into rails console you can see that it has not:

ref = Reference.last
  Reference Load (0.9ms)  SELECT "references".* FROM "references" ORDER BY "references"."id" DESC LIMIT 1
+----+-----+----------+---------+-----------+-------------+
| id |  created_at              | updated_at              |
+----+-----+----------+---------+-----------+-------------+
| 2  |  2012-10-29 11:21:24 UTC | 2012-10-29 11:21:24 UTC |
+----+-----+----------+---------+-----------+-------------+
1 row in set
1.9.2p318 :002 > ref.heuristics
  Heuristic Load (1.0ms)  SELECT "heuristics".* FROM "heuristics" INNER JOIN "footnotes" ON "heuristics"."id" = "footnotes"."heuristic_id" WHERE "footnotes"."reference_id" = 2
 => [] 
1.9.2p318 :003 > Footnote.all
  Footnote Load (0.4ms)  SELECT "footnotes".* FROM "footnotes" 
 => [] 
1.9.2p318 :004 > 

Why is this?

Thanks,

Steven.

BTW, I expected the reference[heuristic_ids][] to dynamically generate the name of each checkbox, but instead the name of each checkbox is the same: reference[heuristic_ids][].

  • 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-14T01:36:46+00:00Added an answer on June 14, 2026 at 1:36 am

    Ensure that the :heuristic_ids (virtual) field is accessible:

    attr_accessible :heuristic_ids # in the model. PLURAL!
    

    Then try to do it in the console (with a bang to show any validation error):

    > Reference.create!("heuristic_ids"=>["", "2"])
    

    this way you’ll get more information about WHY this doesn’t get saved.

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

Sidebar

Related Questions

I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have three models: class Address < ActiveRecord::Base has_many :jobs end class Category <
I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end
I have polymorphic models: class Picture < ActiveRecord::Base belongs_to :imageable, :polymorphic => true end
I have 2 models class User < ActiveRecord::Base has_many :products end class Product <
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have models: class Materialtitle < ActiveRecord::Base has_many :edocs end class Edoc < ActiveRecord::Base
I have the following models: class Constraint < ActiveRecord::Base belongs_to :constraint_category end class ConstraintCategory
I have models: class Model < ActiveRecord::Base has_many :model2 end class Model2 < ActiveRecord::Base
I have 2 models class Category < ActiveRecord::Base belongs_to :parent, :class_name => Category has_many

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.