[Rails] accessing constants in model from controller.

Sam Donaldson samonderous at gmail.com
Sun Sep 10 01:31:41 GMT 2006


Hello,

In my model Example, I've defined three types as such:

class Example < ActiveRecord::Base
  TYPE_A = 'A'
  TYPE_B = 'B'
  TYPE_C = 'C'

  def select....
  end
end

How can I access these types in my controller.  I'm trying the following
with my controller named Read:

def init
  a = Example.TYPE_A
end

It won't allow me to declare the types and gives me a syntax error.  Any
help would be appreciated.  Aren't these just class variable declarations
and should be available through the class?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060910/fdf7e07a/attachment.html


More information about the Rails mailing list