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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:14:50+00:00 2026-05-16T17:14:50+00:00

I’ve been following RailsCast 197 to try this nested models/forms and have cracked my

  • 0

I’ve been following RailsCast 197 to try this nested models/forms and have cracked my head over this code for over 2 hours, but to no avail. What am I overlooking?

I have the following Models:

class Workout < ActiveRecord::Base
  belongs_to :user
  has_many :performed_exercises, :dependent => :destroy
  accepts_nested_attributes_for :performed_exercises
end

class PerformedExercise < ActiveRecord::Base
  belongs_to :workout
  belongs_to :exercise
  has_many :performed_sets, :dependent => :destroy
  accepts_nested_attributes_for :performed_sets
end

class PerformedSet < ActiveRecord::Base
  belongs_to :performed_exercise
end

In my WorkoutsController I have the following:

  def new
    # We only need to build one of each since they will be added dynamically
    @workout = Workout.new
    @workout.performed_exercises.build
    @workout.performed_exercises.performed_sets.build
  end

When I run the test and invoke the controller in the browser, I get the following error:

undefined method `performed_sets' for #<Class:0x7f6ef6fa6560>

Thanks in advance for any help – my RoR noobility ceases to amaze me!

Edit:
fflyer05: I tried using the same code as the RailsCast with the iterating over the collection, as well as attempting to build the performed_sets on performed_exercises[0] – but it doesn’t work. Doing anything else, I get an uninitialized constant PerformedExercise::PerformedSet error

  • 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-16T17:14:51+00:00Added an answer on May 16, 2026 at 5:14 pm

    Model methods should be called on a single object. You are calling them on a collection on objects which will not work, @workout.performed_exercises[0].performed_sets will.

    Notice the code from the Rails cast 196:

    
    # surveys_controller.rb
    def new
      @survey = Survey.new
      3.times do
        question = @survey.questions.build
        4.times { question.answers.build }
      end
    end
    
    

    You would have to loop through each nested method in order to build your form.

    If code like this:

    
    for performed_exercise in @workout.performed_exercises
         for performed_set in performed_exercise.performed_sets
          # something interesting
         end
    end
    
    

    does not work, I would check to be sure that your model file names are correct (rails needs them to be singular) in your case you should have workout.rb,performed_exercise.rb and performed_set.rb for those respective models.

    Your relationships’ definitions look correct, so wrong file names is the only thing I can think of that can be wrong.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
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,
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.