WWW::Mechanize and Rails console not playing well

I can run this code just fine in irb, but when I run it in rails
script/console, I get an error:

res = agent.submit(search_form, search_form.buttons.first)
ArgumentError: one hash required
from /home/jwoods/NetBeansProjects/activista/vendor/rails/
actionmailer/lib/…/…/actionpack/lib/…/…/activesupport/lib/
active_support/core_ext/string/interpolation.rb:85:in %' from /usr/lib/ruby/1.8/webrick/httputils.rb:352:in_escape’
from /usr/lib/ruby/1.8/webrick/httputils.rb:352:in gsub' from /usr/lib/ruby/1.8/webrick/httputils.rb:352:in_escape’
from /usr/lib/ruby/1.8/webrick/httputils.rb:370:in
escape_form' from /usr/lib/ruby/1.8/www/mechanize/util.rb:9:inbuild_query_string’
from /usr/lib/ruby/1.8/www/mechanize/util.rb:6:in map' from /usr/lib/ruby/1.8/www/mechanize/util.rb:6:inbuild_query_string’
from /usr/lib/ruby/1.8/www/mechanize/form.rb:199:in
request_data' from /usr/lib/ruby/1.8/www/mechanize.rb:387:inpost_form’
from /usr/lib/ruby/1.8/www/mechanize.rb:331:in `submit’
from (irb):23

Here’s the code:
#!/usr/local/bin/ruby
require ‘rubygems’
require ‘mechanize’
require ‘logger’
require ‘uri’
require ‘net/http’

agent = WWW::Mechanize.new { |a| a.log = Logger.new(“mech.log”) }
agent.user_agent_alias = ‘Mac Safari’
page = agent.get(‘http://www.fyi.legis.state.tx.us/Address.aspx’)
search_form = page.form_with(:name => “AddressForm”)
search_form.field_with(:name => “Address1”).value = “501 W 26th St,
Apt 110”
search_form.field_with(:name => “City”).value = “Austin”
search_form.field_with(:name => “ZipCode”).value = “78705”
search_form.field_with(:name => “DistrictType”).options[0].select
res = agent.submit(search_form, search_form.buttons.first)

It should return a Mechanize page object.

And no, that’s no longer my address.

What is this interpolation core extension? Why is that causing a
problem? Can I disable it for this lib I’m working on?

Thanks so much,
John

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs