<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; jquery</title> <atom:link href="http://railsnotes.com/tag/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Triggering jQuery code/functions from RJS</title><link>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/</link> <comments>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/#comments</comments> <pubDate>Sat, 25 Apr 2009 02:32:25 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[rjs]]></category> <category><![CDATA[views]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=289</guid> <description><![CDATA[jQuery is an alternative to Prototype, which is the default javascript library inside Rails. Since RJS generates javascript based on prototype, you might think you can't use jQuery in it.  Although it's technically true, you can still use jQuery by using the page.call feature of RJS.]]></description> <content:encoded><![CDATA[<p></p><p>jQuery is an alternative to Prototype, which is the default javascript library inside Rails. Since RJS generates javascript based on prototype, you might think you can&#8217;t use jQuery in it.  Although it&#8217;s technically true, you can still use jQuery by using the page.call feature of RJS. Here&#8217;s an example:</p><p>## test.js</p><pre>$(function(){
  ...
};

function do_something_amazing {
  ... some slick jQuery code ...
};</pre><p>## something.rjs called using link_to_remote or form_for_remote:</p><pre>page.call 'do_something_amazing'</pre><h3>Gotcha</h3><p>A simple gotcha is if you include &#8220;function be_amazing {&#8230;};&#8221; inside the &#8220;$(function(){&#8230;};&#8221;  you&#8217;ll get an undefined error.</p><p>Credits: I came across this approach while helping shipstar in the #rubyonrails IRC channel</p><p><strong>UPDATE:</strong> Using RJS isn&#8217;t the best approach if you value unobtrusiveness. Here&#8217;s a copy/paste of some reasons why &#8220;RJS is evil&#8221;.</p><blockquote><p>dfr|work: it&#8217;s directly coupled to your dom but isn&#8217;t in it.<br
/> dfr|work: i mean, what&#8217;s rjs? it&#8217;s just a callback thing. Just specify it when you&#8217;re making ajax request.<br
/> dfr|work: and if you need the data from server, specify it via json. It&#8217;s clean and simple.</p></blockquote><p>Expect a follow-up to this explaining how to do this the right way.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/289-triggering-jquery-code-functions-from-rjs/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/16 queries in 0.037 seconds using disk

Served from: railsnotes.com @ 2010-09-09 07:31:23 -->