0

I have a problem for hours and hours but I can't find the solution. I find some similar questions to mine, but still no luck. I have a method in my controller :

def get_game_site_log_id(game)
  Game_site_log.connection.select_values("SELECT id FROM game_site_logs 
  WHERE game_id = " + game["game_id"] + "AND site_id = " + @site.id + ";")
end

I got LoadError expected game_site_log.rb to define Game_site_log. I tried to add this :

require File.dirname(__FILE__) + "game_site_log.rb"

But instead of loading the model from game_site_log.rb, it tried to find that file in controller. What is the best solution to this? Thanks :)

2 Answers 2

2
  1. Ruby convention is to name classes in CamelCase, so your model should be named GameSiteLog.
  2. As RoR is heavily using convention over configuration, to get everything running easily you should put game_site_log.rb file in app/models.
Sign up to request clarification or add additional context in comments.

Comments

1

If your model is in app/models/game_site_log.rb then, by Rails conventions, you should define it as:

class GameSiteLog < ActiveRecord::Base
  # methods here
end

Then you can access it with GameSiteLog.connection.select_values().

Class names should be CamelCased and file names should be under_scored.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.