genericuser
genericuser

Reputation: 9

How can I programmatically fill out a remote form with data from another form using Rails?

Requirement: User fills out form A. Data from form A is then passed to form B on another site.

Upvotes: 0

Views: 702

Answers (1)

Matthew Rudy
Matthew Rudy

Reputation: 16844

I suggest you check out mechanize. https://github.com/tenderlove/mechanize

Say the site is http://mysite.com, and there's one field "name" that you want to fill in.

require 'mechanize'

def fill_out_form(name)

  # our agent
  agent = Mechanize.new

  # load mysite.com
  page = agent.get('http://mysite.com')

  # Fill out the form
  form = page.form_with(:name => 'name-form')
  form.name = name
  page = agent.submit(form)
end

then just call this from your controller

FormFiller.fill_out_form(params[:name])


I adapted this form the flickr example https://github.com/tenderlove/mechanize/blob/master/examples/flickr_upload.rb

Upvotes: 3

Related Questions