How do I access my config variable in my helper file?

1.4k Views Asked by At

I’m using rails 5. I have this defined in my config/environments/development.rb file

config.hostname = “myapp.com"

and then I try and access this in a helper file by using

url = "https://#{config.hostname}/lti" 

but this results in an error,

NameError: undefined local variable or method `config' for ScenariosHelper:Module

How do I access my config variable?

2

There are 2 best solutions below

1
On BEST ANSWER

You can access the Rails configuration through Rails.configuration, so use:

Rails.configuration.hostname
0
On

This should work:

url = "https://#{Rails.configuration.hostname}/lti"