Ok i have this in what i have
user.rb //user model
OPTION = ['none', 'all', 'partial']
ANOTHER = ['true', 'false', 'neither']
YET_ANOTHER = ['something', 'another']
application_helper.rb
def my_method(information, name)
#this is where i need help
User::OPTIONS
index.html.erb
my_method('information', :option)
my_method('information', :another)
my_method('information', :yet_another)
How do i in the my_method view helper grab the correct array so for example if i send in
my_method('information', :another)
in the my_method view helper i should execute
User::ANOTHER
I was thinking i could upcase but how to i execute this ….
I tried this below
User::name.upcase
NoMethodError: undefined method `name' for #<Class:0x000d001078cd9c8>
You just need to do the following.
While this works, make sure you aren’t passing user-submitted params into const_get. This would be a security vulnerability, allowing user to essentially execute unintended code. Instead you should simply use a condition.