I'm trying to use Mechanize Ruby to login to a website. I've looked at every example on this site, but an a ruby beginner and get confused as to which page I should even be getting to access the form.
Here's the code I have:
require 'rubygems'
require 'logger'
require 'mechanize'
agent = Mechanize.new
home_page = agent.get('http://www.quora.com')
login_form = home_page.click.form('login')
# with email and password variables properly set
login_form.set_fields(:session_key => 'email', :session_password=> 'password')
return_page = agent.submit(login_form, login_form.buttons.first)
But it's returning the following error:
forge.rb:7: undefined method `click' for #<Mechanize::Page:0x1018592b8> (NoMethodError)
How can you peak behind a page to look at whether a page contains a form?
Also, any idea how to fix the code?