0

I want a list to be available to the whole application, so I put it in constants.rb:

hebrew_consonants = ["א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י", "ך", "כ", "ל","ם","מ","ן", "נ", "ס", "ע", "ף", "פ", "ץ", "צ", "ק", "ר", "ש","ת"]

In application_controller.rb, I use the list as follows:

def is_hebrew?(query)
    (0...query.length).each do |index|
        return true if hebrew_consonants.include?(query[index])
    end
    return false
end

I restarted the server, and the app complained that it didn't know about the list. I put dollar signs before its declaration and its reference ($hebrew_consonants), and it worked. With my other constants, they just work. I guess I thought they were supposed to be global variables just by virtue of being in that class. Why is this one behaving differently?

Thank you

Walrus the Cat
  • 2,314
  • 5
  • 35
  • 64
  • P.S. I know that list declaration looks wacky, but it's just from pasting the right-to-left characters, I think. It does work. – Walrus the Cat May 07 '12 at 08:22

1 Answers1

1

First make sure your constants.rb file is in /config/initializers/. Second, try using all caps for hebrew_constants. From the comments in this SO question it sounds like the all caps is necessary.

Community
  • 1
  • 1
Dty
  • 12,253
  • 6
  • 43
  • 61