Learn-ing
Learn-ing

Reputation: 31

Rails Controller Constant

I am just curious to know whether is there anything as "Controller Constant" in Rails. I have seen people use Model Constants from library or controller. example:

class User
  Author = "me"
end

#Somewhere in controller or lib
p User::Author #me

So Is there Controller Constant, if yes how and where do we use it? and what will be the varieties of constants like model, controller, etc.

P.S: I'm aware of ruby constants, So this question might be wrong. But still I'd like to know the answer. Thanks in advance

Upvotes: 0

Views: 849

Answers (1)

max
max

Reputation: 102368

I am just curious to know whether is there anything as "Controller Constant" in Rails.

No.

Controllers and models are just classes. Classes in Ruby are modules and modules can have nested constants. There is no difference between a constant declared in a controller or model and any other constant in Ruby.

So both models and controllers can have nested constants but calling them "Controller constants" and "Model constants" is nonsensical and will either result in sneers or confusion.

Upvotes: 1

Related Questions