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

Name Error - Ruby on Rails

5   # GET /workorders.json
6  def index
7    @workorders = Workorder.all 
8  end
9
10  # GET /workorders/1

uninitialized constant WorkordersController::Workorder app/controllers/workorders_controller.rb:7:in `index'

5 Answers

Chris McKnight
PLUS
Chris McKnight
Courses Plus Student 11,045 Points

The Rails autoloader is failing to load your Workorder model since it's defined in customer.rb. It is recommended to move your Workorder class into a separate file. Currently, you have it defined in customer.rb.

# app/models/workorder.rb

class Workorder < ActiveRecord::Base
  belongs_to :customer
end

If you want to keep Workorder in customer.rb, take a look at how the Rails autoloading mechanism works and configure your environment appropriately.

Hey Austin,

The error you have encountered is usually found when you are trying to refer to a class or module that does not currently exist or has not been defined yet.

Hope this helps

if i upload it to github could you look at it, i have a good month of work in the app ;(

Sure, but you should be able to fix that error from the error message.

Ive tried, i about deleted the whole application and started over again. but here is the github url

git@github.com:mastertechrv/MTRV_CLOUD.git https://github.com/mastertechrv/MTRV_CLOUD

Hey Austin,

Is it because you have used the plural of workorder in your controller?

Try:

def index
    @workorder = Workorder.all
end

Let me know how it goes.

changed it and still getting the same error

I'm stumped then I'm afraid.

Hopefully someone else will be able to have an input on your question.