Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Dave Faliskie
Dave Faliskie
17,793 Points

Circular dependency detected while autoloading constant

Currently following along with building social features with rails, I am trying to allow a user to "add a friend" except it will be called a job_listing instead. In my project job_listings are not users but a different model. I keep getting an error that says 'Circular dependency detected while autoloading constant ApplyingJob' and refers to my controller for ApplyingJobsController. my applyingJobs table contains a user_id and a job_listing_id

here is my applying_jobs controller

class ApplyingJobsController < ApplicationController

    before_action :require_user

    def new 
        if params[:job_listing_id]
            flash[:notice] = "got job id"

            @job_listing = User.find(params[:job_listing_id])
            @applying_job = current_user.applying_jobs.new(job_listing: @job_listing)


        else
            flash[:error] = "Job Listing Required"
        end

    rescue ActiveRecord::RecordNotFound
        render file: 'public/404', status: :not_found
    end


    def applying_job_params
      params.require(:applying_job).permit(:user_id, :user, :job_listing_id, :job_listing)
    end
end

What I am trying to do is save a users_id and a job_listing_id into my applyingJobs table(relationship table). Is this even how you would do it?

I think this line has a problem but I don't know what to do to fix it.

 @applying_job = current_user.applying_jobs.new(job_listing: @job_listing)

if anyone knows of anything that I am overlooking that could possibly fix this it would be greatly appreciated

1 Answer

Brandon Barrette
Brandon Barrette
20,485 Points

Your new method is not being ended. You need another end after your rescue.