bdwain
bdwain

Reputation: 1745

rails model helper class not loading

I have a Game model, and in my model, I want to use a helper class, GameBoard. I tried to create game_board.rb in app/helpers, and then use it in my game model.

#game_board.rb
class GameBoard
  def initialize(foo)
     #stufff
  end
end

#in after_intialize in game.rb
@board = new GameBoard(foo)

However, when trying to create a game, it fails to create the GameBoard, saying

NoMethodError: undefined method `GameBoard' for Game:0x00000005309df0

I tried requiring game_board.rb at the top of the file and that didn't work. Does anyone know what I'm doing wrong?

Thanks.

Upvotes: 0

Views: 286

Answers (1)

Ivan Antropov
Ivan Antropov

Reputation: 414

All files from app/ directory automatically loaded by Rails. So, for instantiate a new object you should use (http://www.ruby-doc.org/docs/ProgrammingRuby/html/intro.html )

GameBoard.new(foo) 

instead of

new GameBoard(foo)

Upvotes: 2

Related Questions