LewlSauce
LewlSauce

Reputation: 5862

Rails doesn't recognize my new class

I'm so confused as to why this isn't working. So inside of a controller, I have something that looks like this

#controllers/report_controller.rb
def new
  test = GenerateReport.generate(data)
end

and then I have a model that looks like this:

#models/generate_report.rb
class GenerateReport < ActiveRecord:Base
   def self.generate(data)
      # some code
   end
end

When my controller hits the "new" action, it actually works. However, if I renamed GenerateReport to GenerateReportX and change the function in the controller accordingly, restart the rails app, it doesn't recognize GenerateReportX. I don't get why this is the case? I'm renaming everything that says GenerateReport in the whole rails app and restarting the app completely.

My actual problem was that a new model that I've created is almost an exact mimick of the one that works fine (without me renaming it), and its class isn't being recognized.

I've tried adding this config.autoload_paths += %W(#{config.root}/lib) to application.rb and that doesn't fix anything.

Any suggestions and possibly clarification on this issue?

Upvotes: 1

Views: 1144

Answers (1)

Roman Usherenko
Roman Usherenko

Reputation: 5639

If the class is named GenerateReportX it has to live in models/generate_report_x.rb

Upvotes: 3

Related Questions