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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:51:38+00:00 2026-05-23T03:51:38+00:00

I have a three models: Homework , Question , and HomeworkAttempt . homework.rb :

  • 0

I have a three models: Homework, Question, and HomeworkAttempt.

homework.rb:

class Homework < ActiveRecord::Base
  belongs_to :group
  has_many :questions
  has_many :homework_attempts
end

question.rb:

class Question < ActiveRecord::Base
  belongs_to :homework
end

homework_attempt.rb:

class HomeworkAttempt < ActiveRecord::Base
  belongs_to :homework
  belongs_to :student
  has_many :answer_attempts
end

I setup two controllers, thinking this would be the best way. My homework controller is empty, and exists simply for nesting the homework_attempt. My homework attempts controller looks like this:

class HomeworkAttemptsController < ApplicationController
  def new
    @group = Group.find(params[:group_id])
    @homework = Homework.find(params[:homework_id])
    @questions = @homework.questions
    @homework_attempt = HomeworkAttempt.new
    current_user.homework_attempts << @homework_attempt
    @title = @homework.name
  end
  ...
end

I want to set it up so that the user can create a new homework attempt based on the homework. How should I go about doing this? What columns will I need in my model?

Thanks!

  • 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-23T03:51:38+00:00Added an answer on May 23, 2026 at 3:51 am

    I can’t tell exactly what you’re asking, but I have some ideas that might help you get started:

    In your relations, it seems like you’re trying to use models that you never created. For example, belongs_to :group and has_many :answer_attempts both imply that those models exist, but you haven’t mentioned them anywhere else. If you want to use these relations, you must create these models.

    Also, it seems like you’re doing too much work in your new action. The fourth line is usually all that’s needed in such an action, but it is hard to tell without more detail on what exactly you’re trying to accomplish.

    You will need much more than you’ve shown here to make this all work. You really ought to have a controller to manage the CRUD for each of your models, unless you have some other plan that I’m not seeing. If you provide more information on what you currently have and what you’re trying to get to, I can edit my answer to try to be more helpful.

    • 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 Address < ActiveRecord::Base has_many :jobs end class Category <
I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end
I have three models defined as follows: class Comic < ActiveRecord::Base has_many :feeds end
I have three models: class Tenant < ActiveRecord::Base has_many :sites end class Site <
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I have three Models setup with the following associations class User < ActiveRecord::Base has_many
I have three models presented in a multi-model form. class Parent < ActiveRecord::Base has_many
I have three models connected via an has_many_through association. class Board < ActiveRecord::Base has_many

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.