title: One to Many Relationship between receipt and subject
body: <p>I am working on a school project and i'm new to ROR.  I have two objects, Receipts and Subjects.  The receipts have one subject and the subjects are reused among the receipts.  I don't have a problem if I have equal number of subjects to receipts, but when I don't create a new subject for a receipt I get this error </p>
  
  <p><a href="https://i.stack.imgur.com/olPjP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/olPjP.png" alt="enter image description here"></a></p>
  
  <p>The problem here is I only have two subjects in the database with 3 receipts. So an id of 3 is invalid. My models, views, controllers, and migrations are follow.</p>
  
  <p>Models: 
  class Receipt &lt; ActiveRecord::Base belongs_to :user has_one :subject, :foreign_key => :id validates :user_id, presence:true validates :descript, presence: true, length: { minimum: 4, maximum: 120 } end</p>
  
  <p>class Subject &lt; ActiveRecord::Base has_many :receipts validates :subject_name, presence: true, length: { minimum: 2, maximum: 30 } validates :description, presence: true, length: { minimum: 2, maximum: 200 } end</p>
  
  <p>Controller:
  def index @receipts = Receipt.paginate(page: params[:page], per_page: 4).order("updated_at DESC") end</p>
  
  <p>Migration: 
  class CreateReceipts &lt; ActiveRecord::Migration def change create_table :receipts do |t| t.datetime :date t.decimal :tax_amount, :purchase_amount, precision: 5, scale: 2 t.boolean :approved, default: false t.text :descript t.integer :user_id, :subject_id, t.timestamps end end end</p>
  
  <p>class CreateSubjects &lt; ActiveRecord::Migration def change create_table :subjects do |t| t.string :subject_name t.text :description t.timestamps end end end </p>
  
  <p>View: </p>
  
       
  
  <p>I think my migration and views are fine since it works when I have equal subjects to receipts,</p>