railsman
railsman

Reputation: 152

How to dynamically call variables defined in initializers in rails

I want to dynamically call variables defined in initializers. I have a created a file(brands.rb) in my initializers and it have some variable defined init like,

FEATURED_FASHION_BRAND=["something", "something"]
FEATURED_DIY_BRAND=["something", "something"]

so can I call this variables dynamically, I meant, something like this,

@name= params[:name]
FEATURED_"#{@name}"_BRAND

Upvotes: 0

Views: 506

Answers (1)

Fer
Fer

Reputation: 3347

you can use constantize for that:

"FEATURED_#{@name}_BRAND".constantize

Upvotes: 1

Related Questions