Friday, November 16, 2007

RJS is Supported Now

I'm sorry that I enable jq4r support RJS so lately. From the revision #27 on, you can use some (not all) RJS methods while you use jq4r. For instance,


  • jquery_insert_html(position, id, *htmls)


    You can insert html by using this method. The first parameter specifies the insertion position like 'before', 'after', 'wrap', and so on. For more details, please refer the jQuery/Manipulation's documentation.

  • jquery_replace_html(position, id, *htmls)


    This method replace the html by using the jQuery.html function.

  • jquery_replace(id, *htmls)


    It will replace the specified element with the *html.

  • jquery_remove(*id_list)


  • jquery_hide(*id_list)


  • jquery_show(*id_list)


  • jquery_toggle(*id_list)


  • jquery_visual_effect(name, id, options)



Please try the HEAD revision of jq4r and feel free to send me any suggestion if you find something wrong out. :-)

Wednesday, November 14, 2007

jq4r 0.1.1 Released and Fix jQuery/Ajax's Bug

jq4r has a new release. Version 0.1.1 fixes some bugs in 0.1:


  • lib/jq4r.rb

    Fix jquery_visual_effect method's bug. (speed parameter doesn't be quoted)

    Use alias_method to replace the method's prefix from jq_ to jquery_



  • install.rb

    The script of installing the necessary files for jq4r.

  • javascripts/jq4r.js

    Combine the jquery-1.2.1.js and jquery.form.js into jq4r.js and patch the jQuery/Ajax's bug.


If you use the subversion to install jq4r, please update you repository to the HEAD revision.

On the other hand, jQuery/Ajax has a little bug, that is, jQuery doesn't set Accept header on Ajax call so that there's problem while you use respond_to in Rails. Thanks for Jason Yate's patch, the script in version 0.1.1 (and HEAD revision) has been patched.

Thanks for every helps from you all :-)

Thursday, November 8, 2007

Combine the JS files

Since the common browsers create ONLY 2 HTTP requests at the same time on loading a page, I decide to combine the seperated JavaScript files into one jq4r.js file. If you have installed this plugin, follow these steps:


  1. Update from the repository

  2. Remove the original ${RAILS_ROOT}/public/javascripts/jquery.js and ${RAILS_ROOT}/public/javascripts/jquery-form.js

  3. Re-execute rake jq4r:install for installing the new jq4r.js file.


You NEVER need to modify your source.

In the following revisions, I will put all the JavaScript code in jq4r.js. How do you feel about it?

Sunday, November 4, 2007

The form tag use POST method by default

At revision 20, I add one line code that makes the jquery_form_remote_tag use 'POST' method (or type, in jQuery/Ajax convension) by default.

Thanks lamys***@hotmail for providing this solution at the project's issue page on Google code.

Wednesday, October 24, 2007

Canonical Pathname

In order to install jq4r more conveniently, I decide to change the path in the SVN repository. Now you need ONLY 1 step to install jq4r:

script/plugin install http://jq4r.googlecode.com/svn/trunk/plugins/jq4r

You never need to execute rake jq4r:install any more because I clone the task into install.rb so that the Rails's script/plugin would automatically execute the installation process.

Wednesday, September 26, 2007

Prefix jq_ OR jquery_ ?

After I release the version 0.1, some people told me that it would be better that use jquery_ as the helpers' prefix. The reason is that the helpers with jquery_ prefix are more readable. I accepted this suggestion and from version 0.2 on, each helper will use jquery_ as its prefix.

This change, of course, is compatible with the jq_ prefix because I use the alias_method to make them compatible. That's why Ruby is so popular -- powerful, elegant, and easy. :-p

jq_visual_effect's bug

There's a little bug in version 0.1. The jq_visual_effect helper generates the default speed with an unquoted string. For example, it should be:

$('#me').fadeTo('normal', opa, function(){});

but the buggy method generates:

$('#me').fadeTo(normal, opa, function(){});

There are 2 ways to eliminate this bug.


  1. You can pass the :speed argument with "'slow'", "'normal'" or "'fast'" (i.e. add the quote yourself).

  2. The other way is to modify the jq_visual_effect helper in lib/jq4r.rb and add quotes around ${speed}.

Sunday, September 23, 2007

What will be done in 0.2?

I want to add jQuery UI helpers in version 0.2. Although this jQuery plugin has simplified the code of writing web UIs, it could be more easier to RoR developers if some ``templates'' are included in the jq4r plugin.

If you want to use another features in jq4r, please tell me :-)

Thursday, September 20, 2007

jq4r version 0.1 released

In jq4r version 0.1, the following helpers are provided:

  • jq_link_to_remote

    This method works as the original link_to_remote method. It creates a link tag but overrides the click event handler to send request to a remote action. The relationship between jq_link_to_remote and link_to_remote is that jq_link_to_remote is a jQuery-based implementation of link_to_remote
  • jq_load_from_remote

    This method also creates a link to a remote action but update the content (innerHTML) of a element by the response of a remote action. It's a simplified version of jq_link_to_remote, because it simply generates $(elem).load() script instead of $.ajax(...).
  • jq_form_remote_tag

    As the original form_remote_tag, it creates the form tag and overrides the submit event handler. jq_form_remote_tag is the jQuery-based implementation of form_remote_tag.
  • jq_remote_form_for

    As jq_form_remote_tag, this method is another way to create the form tag with AJAX actions.
  • jq_submit_to_remote

    Creates a button tag (accurately, an input tag) thats submit data to a remote action. If the data are not specified, it will submit whole fields' values within a form.
  • jq_periodically_call_remote

    Requests a remote action periodically. With :frequency option you man specify how long is the request be fired.
  • jq_observe_field

    Observes a field within a form. While the timer event comes (if you specify the :frequency option) or there's something changed within the field, the callback function will be executed.
  • jq_observe_form

    As jq_observe_form, it observes a form, instead.
  • jq_visual_effect

    By calling jq_visual_effect, you can make animations in the page. As the original visual_effect, the first parameter is the effect's name. In jq4r version 0.1, you may use :animate, :slide_up / :slide_down, and :fade_in / :fade_out / :fade_to.
I will try to make jq4r supports more jQuery methods or plugins. Just give it a trial, and feel free to send me feedbacks to make jq4r much better. Thanks.

Check jq4r out!

The Rails framework installed the Prototype.js & Scriptaculous as its default JavaScript framework and defined many useful helper methods for easing the design of JavaScript(especially, AJAX).

jq4r is a Rails plugin, which installs the jQuery JavaScript framework and provides useful helper methods, too. I wish this plugin also eases the design of the javascripts and make your RHTML clean.

Just go to the jq4r project's page, and send me feedbacks if you have interesting ideas or suggestions.