# WWW::Mechanize and Rails console not playing well

**URL:** <https://www.ruby-forum.com/t/www-mechanize-and-rails-console-not-playing-well/176139>\
**Category:** Rails\
**Created:** [September 25, 2009, 6:15am UTC](https://www.ruby-forum.com/t/www-mechanize-and-rails-console-not-playing-well/176139 "2009-09-25T06:15:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [September 25, 2009, 6:15am UTC](https://www.ruby-forum.com/t/www-mechanize-and-rails-console-not-playing-well/176139/1 "2009-09-25T06:15:56Z")

</div>

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:in `build\_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:in `build\_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:in `post\_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](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
