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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:47:08+00:00 2026-05-31T04:47:08+00:00

I’m having difficulties getting an association to work with simple_form . I have the

  • 0

I’m having difficulties getting an association to work with simple_form.

I have the following models.

class Product < ActiveRecord::Base
  belongs_to :Retailer
end

and

class Retailer < ActiveRecord::Base
   has_many :Products
end

My form partial (products/_form.html.erb) contains the following

<%= simple_form_for(@product) do |f| %>
...
<% f.input :currency %>
<% f.association :retailer %>
...

It works without the association, but with it I get the following error:

undefined method `retailer_id' for #<Product:0x007ffbe0f7d530>

I’m (obviously) quite new to this, but haven’t been able to work this out.

edit: checked I’d run migrations and they are up-to-date. The Retailer table has an id column!

> Retailer.all
Retailer Load (0.2ms)  SELECT "retailers".* FROM "retailers" 
=> [#<Retailer id: 1, name: "Retailer 1" etc...

chema file:

ActiveRecord::Schema.define(:version => 20120308195055) do

  create_table "alerts", :force => true do |t|
   t.string   "url",        :null => false
   t.datetime "created_at", :null => false
   t.datetime "updated_at", :null => false
  end

  create_table "products", :force => true do |t|
      t.string   "title",                      :null => false
      t.integer  "price_cents", :default => 0, :null => false
      t.string   "currency",                   :null => false
      t.string   "asin",                       :null => false
      t.datetime "created_at",                 :null => false
      t.datetime "updated_at",                 :null => false
  end

    create_table "retailers", :force => true do |t|
      t.string   "name",       :null => false
      t.datetime "created_at", :null => false
      t.datetime "updated_at", :null => false
    end

  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-05-31T04:47:10+00:00Added an answer on May 31, 2026 at 4:47 am

    Since you have belongs_to :Retailer and <% f.association :retailer %> in your model and form for Product respectively, you’ll need to add a retailer_id column to your products table.

    You are missing t.references :retailer in your migration file for creating products table.
    That is why, I quote you “it works without the association, but with it the error is undefined method 'retailer_id' for #<Product:0x007ffbe0f7d530>“

    Yes, the retailers table has an id column but in order to reference a retailer from a product, your products table requires a retailer_id column.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.