I'm attempting to log in to a website but my env variables are not inserting properly in the necessary form. I am using Figaro and my environment variables are safely stored in config/application.yml
. I can confirm two things...
- When hard-coding my actual email and password, I am able to log in successfully
My environment vars return properly when testing in the Rails console (e.g. ENV["WHATEVER"] returns the proper value)
# app/helpers/scrape_wf.rb require 'mechanize' agent = Mechanize.new page = agent.get('https://www.wealthfront.com/login') login_form = page.forms.first # LOG IN UNSUCCESSFUL login_form.email = ENV["WF_EMAIL"] login_form.password = ENV["WF_PASSWORD"] home_page = login_form.submit puts page.title # => Log In to Wealthfront puts home_page.title # => Log In to Wealthfront # LOG IN SUCCESSFUL login_form.email = "my_harcoded_email" login_form.password = "my_harcoded_password" home_page = login_form.submit puts page.title # => Log In to Wealthfront puts home_page.title # => Wealthfront
and in the console...
rails c
Loading development environment (Rails 4.2.4)
[1] pry(main)> ENV["WF_EMAIL"]
=> "my_harcoded_email"
[2] pry(main)> ENV["WF_PASSWORD"]
=> "my_harcoded_password"
What am I doing wrong...?