Using environment variables in controller (Rails) -
i'm trying display sendgrid email statistics inside rails application.
so far, i've been able display them in api's return format (e.g. [{"delivered"=>9, "unsubscribes"=>0, "repeat_bounces"=>2,....
), that's if put plaintext username , password controller's private method because cannot seem use 'sendgrid_username'
, 'sendgrid_password'
environment variables. what's guy do?
in summation:
newsletterscontroller:
before_action :set_client, only: :index private def set_client @client = sendgridwebapi::client.new('the plaintext username', 'the plaintext password') end
newsletters index view
<p><%= @client.stats.get %></p>
is there place can set @client
view can , plaintext password can hidden outside world? preferably place can put in secrets.yml
?
@client = sendgridwebapi::client.new('sendgrid_username', 'sendgrid_password')
returns incorrect username , password, though got plaintext username , password i'm using testing from variables, know they're set correct ones.
or, there way use environment variables in either controller or view?
i'm able set variables in rails console , use them, since don't saved can't access them afterwords in actual application.
although solution not secrets.yml, works fine.
# config/initializers/my-supersecret-vars.rb env['sendgrid_username'] = 'my_super_secret_username' env['sendgrid_password'] = 'my_super_secret_password'
just remember add on .gitignore
Comments
Post a Comment