Ruby on Rails
Inject Plugin

The Inject Plugin allows you to do things similar to remote_link and remote_form only for cross-domain calls. Most browsers don’t allow xmlhttp requests to be cross-domain (ie. from yourdomain.com to otherdomain.com), the javascript included in this plugin inserts script tags into the existing HTML to do GET requests to a server, these GET requests are allowed by all the major browsers.

svn: https://fngtps.com/svn/rails-plugins/trunk/inject

Ok, let’s start with a quick example.

<%= form_inject_tag :url => url_for(:only_path => false, :controller => 'comment',
  :action => 'add'),
  :before => "Effect.toggle('button')",
  :confirm_crop_message => "Your message is too long. If you send it, it will" +
    "be cropped. Please shorten your message and try again.",
  :on_cancelled_crop => "Effect.toggle('button') %>
  <%= text_area 'comment', 'body' %><br />
  <%= submit_tag 'Send' %>
<%= form_end_tag %>

This form will work similar to the normal form_remote_tag form. It will create some javascript for posting the form to the URL. The contents of the form will get encoded to a GET string and sent to the server.

The only technical problem lies in this GET string. Internet Explorer doesn’t support unlimited length GET strings (and doesn’t have to according to the standard). When the GET string gets too large the :confirm_crop_message will be displayed in a javascript alert. There are more options to control this behavior.

Included helpers:

inject_function: Inject version of remote_function

form_inject_tag: Inject version of form_remote_tag

link_to_inject: Inject verison of link_to_remote

Please see the documentation included with the plugin for more information about options for these helpers.