lundi 22 août 2016

How to set correct namespace in Rails models?

In app/models/sudoku, I have 6 classes.

  1. app/models/sudoku/sudoku.rb
  2. app/models/sudoku/board.rb
  3. app/models/sudoku/cell.rb
  4. app/models/sudoku/row.rb
  5. app/models/sudoku/column.rb
  6. app/models/sudoku/block.rb

class Sudoku < ActiveRecord::Basecalls class Board, and class Board calls class Cell, class Row, etc. Like this:

- sudoku.rb 
 - board.rb
   - cell.rb
   - column.rb
   - row.rb
   - block.rb

When I run the code on class Sudoku, I get a Unable to autoload constant Sudoku::Board error. I understand this completely, that when you add a new sub-dir into the models dir, you need to have the name space convention.

But, when I name app/models/sudoku to app/models/foo, I don't have to use ANY name space.

Why does this happen?

Aucun commentaire:

Enregistrer un commentaire