'Heroku error when adding an Environment Variable that is a Comma Separated Value with Spaces

Here is a variable that is defined in my local .env file in my app. I created it to be a comma separated value, like so:

 STATE_KEYWORDS=georgia,new york,new jersey,maine,vermont,florida 

In my seed.rb file, I call on that STATE_KEYWORDS variable by using the "fetch" and "split" methods to turn it into an array, because I need that attribute ("keywords") to be an array:

 Category.create(name: "U.S. States", keywords: ENV.fetch("STATES_KEYWORDS").split(","))

This works fine when I run my app remotely, but when I push to Heroku, it seems as if Heroku is not recognizing/picking up the .env file. So I tried to add the variable like this:

heroku config:add STATE_KEYWORDS=georgia,new york,new jersey,maine,vermont,florida

But then I get this error:

 new york,new jersey,maine,vermont,florida
 is invalid. Must be in the format FOO=bar.

I don't think it likes the space between "new" and "york". Or "new" and "jersey"...etc. It wants it to be one fluid value.

But I need the "keywords" array to equal the below, with some elements in that array being 2 or 3-worded strings:

 keywords: ["georgia", "new york", "new jersey", "maine", "vermont", "florida"]

How can I do this? How can I add this .env variable to Heroku (i'm not married to leaving them in an .env file, I just can't have them pushed up to my Github/Heroku in plain view, for everyone to see. Those keywords have to be hidden...which is why locally I had them in a .env file.

Also, I have ".env" in my.gitignore file, which is why I successfully pushed to Github without that file appearing there.



Solution 1:[1]

Remove Spaces when you are commanding! like

incorrect heroku config:set key= value correct heroku config:set key=value

Solution 2:[2]

Try this:

STATE_KEYWORDS='georgia,new york,new jersey,maine,vermont,florida'

Solution 3:[3]

Remove any spaces in your .env file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shahzaib manzoor
Solution 2 Buck3000
Solution 3 Paul Munyao