mad.ly rails, jquery, flash, etc    about »

Posted by
Scott McMillin

Posted
22 August 2007 @ 6pm

Tagged
jquery, rails

2 Comments

RailsEdge – Chicago

Geoff and I will be attending RailsEdge in Chicago this weekend. If you see us there be sure to ask Geoff about his jQuery for Rails plugin that he has developed and that we’ve been using for the past couple of months in a number of projects.


Posted by
Geoff Buesing

Posted
21 May 2007 @ 11pm

Tagged
ajax, javascript, jquery, rails, rjs, ruby

6 Comments

Integrating jQuery and Rails: use unobtrusive Javascript instead of view helpers

The jQuery Way to apply behavior to a document is to add it unobtrusively via the $(document).ready() function, ideally in an external script file… unlike the Rails Way, which is to add behavior to individual elements via inline Javascript, using the built-in view helpers.

The markup generated by these helpers is obtrusive, and often repetitive. For example, using the built-in link_to_remote helper like this:

< % for post in @posts -%>
< %= link_to_remote post.title, :url => post_path(post) %>
< % end -%>
 

…generates this HTML:

<a onclick="new Ajax.Request(‘/posts/1′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 1</a>
<a onclick="new Ajax.Request(‘/posts/2′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 2</a>
<a onclick="new Ajax.Request(‘/posts/3′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 3</a>

… which is obtrusive, non-degradable and non-DRY. [Read more →]


Posted by
Geoff Buesing

Posted
17 May 2007 @ 11pm

Tagged
ajax, javascript, jquery, rails, rjs, ruby

15 Comments

JQuery Ajax + Rails

UPDATE
Old stuff here! See Errtheblog’s post on jQuery for more up-to-date information…

***

I’ve been working on integrating jQuery’s Ajax capabilities into a Ruby on Rails application; here’s what I’ve discovered so far:

RJS templates (yes, you can use them!)

UPDATE see Javascript + embedded Ruby templates with Rails, out-of-the-box for a way to skip using RJS templates altogether and write .js.erb templates (Edge Rails only.)

After playing around a bit with various options (like rendering Javascript from a standard .rhtml partial) I was surprised to discover that I could use RJS templates to write jQuery-specific Javascript.

Given that the Prototype syntax for element proxies — $(id) — is the same syntax as the jQuery object — $(selector) — the RJS element proxy syntax — page['someid'] — can be used to output a jQuery object. Built-in method_missing magic handles the arbitrary methods chained to it. Examples:

page["#posts"].append render(:partial => ‘post’, :locals => {:post => @post})

#=> $("#posts").append("Post #29 info…");

page[".hide-this"].hide

#=> $(‘.hide-this’).hide();

page["#foo"].html("bar").append("baz")

#=> $("#foo").html("bar").append("baz");

page["h1"].add_class "make-red"

#=> $("h1").addClass("make-red");

[Read more →]


After →