Rails AJAXed REGEX Real-Time Tester

Provides: An example of how to use AJAX in Rails to monitor and test two fields, using observe_form() .

1) First field is a user entered regular expression (regex).

2) Second field is a text string to pass the regular expression.

regax is a rewrite of a php based app created to assist end-users in the development of regular expressions, and to provide feedback on the text they needed to pass against a pattern.

Why?: 1) The php version worked fine, but did not have the 'real-time' feel to it that AJAX is well suited for. Ruby on Rails provides a very quick and easy method to deploy AJAXed web pages.

2) This provided an opportunity to examine the dynamic possibilities of AJAX in a form, with dependencies among multiple fields.

Usage: The initial screen shows the two blank fields.

Illustration 1

When starting the regex definition, the ruby function will complain if passed an intermediate string that is not finished being 'formed'.

The error trap 'rescue RegexpError' takes care of that, and provides 'real-time' feedback to the user (see Illustration 2) via Expression Error: $...

Illustration 2

In the following screen, the regex entry is valid (according to but the Test Text (nil at this point) does not pass the pattern, so the message “FAIL” is displayed. (See Illustration 3)

Illustration 3

In the following screen, the Test Text “PASS”es the regex pattern. The user is presented a status in “Real Time” just above the Test button.

If the user is not sure if the pattern has been checked (poor AJAX connection?) then they can submit via the “Test” button (the old way).

Illustration 4

The following section shows the 'old, pre-Web2.0 way' of working. For browsers that do not support/enable javascript.

If the user clicks the 'Test' button, the form will be submitted to 'results' method and view, and displayed as shown in Illustration 5, below.

Illustration 5