views:

30

answers:

3

Hey!

I am creating a rails3 application and I want to create a class that handles string formatting, so I made a class called FormatUtilites.rb in the lib directory but whenever I try calling it from somewhere else in my app I get this error:

ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::FormatUtilities)

So it thinks its a constant and not a class method, which is how it is defined. Any ideas?

class FormatUtilities

  def self.slugify(name)
    name.downcase.gsub(/\s|\W|\D/, "")
  end

end

Thanks!

+1  A: 

Classes are constants in Ruby, besides also being classes. Probably you just need to do "require format_utilities"

centipedefarmer
but arent files from the lib directory supposed to autoload?
Daniel Hertz
A: 

If you want rails to automatically load this file when it boots, you will need to name your file format_utilities.rb. The next time you restart your server or console, you should be able to do FormatUtilities.slugify("name")

Beerlington
i tried that but i still get the same error :(
Daniel Hertz
+4  A: 

Turns out rails3 stop autoloading the lib directory. I have no idea why they did it, but they did. Just needed to add it to the autoload in the application.rb

thanks anyways!

Daniel Hertz