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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:10:35+00:00 2026-06-16T23:10:35+00:00

I have three models, users, reports, and receipts. Users have many reports, and reports

  • 0

I have three models, users, reports, and receipts. Users have many reports, and reports have many receipts.

Now, I have a form set up to create, or edit reports. And I need to nest another form to create and edit receipts. I followed the rails guide (section – building a multi modeled form) and edited my models, and have added the build line into my form view but Im getting that ‘uninitialized constant’ error.

Here are my models:

class Report < ActiveRecord::Base
  belongs_to :user
    has_many :receipts

  attr_accessible :cash_advance, :company, :description, :end_date, :mileage, :report_name,
  :start_date, :receipts_attributes

    validates_presence_of :company, :description, :end_date, :report_name#, :start_date
    validates_uniqueness_of :report_name

    accepts_nested_attributes_for :receipts, :allow_destroy => :true,
    :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end

class Receipts < ActiveRecord::Base
  belongs_to :report
  attr_accessible :account_code, :amount, :company_card, :date, :description, :lobbying_expense, :vendor
end

and my form:

<%# @report.receipts.build %>
<%= form_for([current_user,@report]) do |f| %>
     ...
    <%= f.fields_for ([@report, @report.receipts.build ]) do |receipt| %>
     ...
    <% end %>
<% end %>

my routes (which Im not sure if I should have edited, but I got the same error before I added the receipts resources)

resources :users do
    resources :reports do
        resources :receipts
    end
end

I didnt edit the reports controller since the rails guide didnt show any mention of it, its its only:

def new
@report = current_user.reports.new
end

def edit
@report = current_user.reports.find(params[:id])
end

What am I doing wrong?

edit – I changed my form for the receipts so the form_for takes in [@report, @report.receipts.build] but now I get the error:

uninitialized constant Report::Receipt

How do I get this form to work?

  • 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-16T23:10:37+00:00Added an answer on June 16, 2026 at 11:10 pm

    UGH! I messed up when I generated the model and gave it a plural name instead of a singular name. This guy, right here, is a fool.

    • 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 that are coming together to create one view model and
I have three models: User Award Trophy The associations are: User has many awards
I have three models, Poem and Song and User . Users can vote on
I have three models: products , users , and reviews . A review is
In my app, I have three models: Markets, Deals, and Users. Relationships are pretty
Possible Duplicate: CakePHP Subscribe Users Model I have three models User Post Friendship What
I have three models: User Image Group . User belongs to an image; Group
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have three models: Post , Comment , User and Vote . I'm using

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.