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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:39:50+00:00 2026-06-03T00:39:50+00:00

class Product < ActiveRecord::Base has_many :models, :dependent => :destroy, :order => ‘display, title’ class

  • 0
class Product < ActiveRecord::Base
  has_many :models, :dependent => :destroy, :order => 'display, title'

class Model < ActiveRecord::Base
  belongs_to :product

class GsCollector < ActiveRecord::Base
  belongs_to :model

Why can’t I do the following in my form for GsCollector?:

  <p>
    Model:<br />
    <%= collection_select :gs_collector, :model_id, Product.where("title = 'Some Title'").models.all, :id, :title %>
  </p>

I get the error:

undefined method `models' for #<ActiveRecord::Relation:0x007fef0ac09350>

Shouldn’t the models method be provided by the relation? In the console, this works:

p = Product.find(4).models

But this doesn’t:

p = Product.where("title = 'some title'").models

Not sure what the difference is….

Here’s my schema:

  create_table "gs_collectors", :force => true do |t|
    t.integer  "project_id"
    t.integer  "model_id"
    t.integer  "quantity",   :default => 1
    t.string   "housing",    :default => "Base Unit"
    t.string   "hopper"
    t.string   "controller"
    t.boolean  "overbags",   :default => false
    t.datetime "created_at",                          :null => false
    t.datetime "updated_at",                          :null => false
  end

  create_table "models", :force => true do |t|
    t.string   "title"
    t.integer  "product_id"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "display"
  end


  create_table "products", :force => true do |t|
    t.string   "title"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  • 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-03T00:39:51+00:00Added an answer on June 3, 2026 at 12:39 am

    You are returning an array of objects, collectively called a ActiveRecord::Relation. This is due to your where search term. Maybe you want something like the following:

    p = Product.find_by_title('some title').models
    

    where returns a list of Products

    find returns a single Product

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

Sidebar

Related Questions

I have the following models: class Release < ActiveRecord::Base has_many :products, :dependent => :destroy
I have the following models: class Product < ActiveRecord::Base belongs_to :brand belongs_to :model accepts_nested_attributes_for
I have the following model structure: class Group < ActiveRecord::Base has_many :group_products, :dependent =>
Models code: class Product < ActiveRecord::Base has_and_belongs_to_many :product_groups belongs_to :accessible_fields_group named_scope :sort_by_priority, :joins =>
I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price
I have a the following models: class Release < ActiveRecord::Base has_many :products, :dependent =>
I have 2 models class User < ActiveRecord::Base has_many :products end class Product <
I have the following two models: class Product < ActiveRecord::Base belongs_to :shop validates_numericality_of :price,
I have two models. order and line_item. class Order < ActiveRecord::Base has_many :line_items has_many
I have a Product model: class Product < ActiveRecord::Base belongs_to :subcategory define_index do #

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.