<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Javascript + embedded Ruby templates with Rails, out-of-the-box</title>
	<atom:link href="http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/feed/" rel="self" type="application/rss+xml" />
	<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/</link>
	<description>rails, jquery, flash, etc</description>
	<lastBuildDate>Sun, 20 Dec 2009 21:02:36 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: jean-sébastien</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1702</link>
		<dc:creator>jean-sébastien</dc:creator>
		<pubDate>Mon, 03 Dec 2007 10:49:11 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1702</guid>
		<description>here is an additionnal helper method to use remote links &quot;jquery way&quot; using protect_from_forgery 
I should precise that i use an additionnal class (.put .post .delete) which determines ajax method.

def remote_link_to(name, options = {}, html_options = nil, *parameters_for_method_reference)
    options += (options.include?(&#039;?&#039;) ? &#039;&amp;&#039; : &#039;?&#039;) + 
      &quot;#{request_forgery_protection_token.to_s}=#{form_authenticity_token}&quot;
    html_options[:class] = html_options.has_key?(:class) ? 
      html_options[:class].to_s + &#039; remote&#039; : &#039;remote&#039;
    link_to(name, options, html_options)
  end</description>
		<content:encoded><![CDATA[<p>here is an additionnal helper method to use remote links &#8220;jquery way&#8221; using protect_from_forgery<br />
I should precise that i use an additionnal class (.put .post .delete) which determines ajax method.</p>
<p>def remote_link_to(name, options = {}, html_options = nil, *parameters_for_method_reference)<br />
    options += (options.include?(&#8216;?&#8217;) ? &#8216;&amp;&#8217; : &#8216;?&#8217;) +<br />
      &#8220;#{request_forgery_protection_token.to_s}=#{form_authenticity_token}&#8221;<br />
    html_options[:class] = html_options.has_key?(:class) ?<br />
      html_options[:class].to_s + &#8216; remote&#8217; : &#8216;remote&#8217;<br />
    link_to(name, options, html_options)<br />
  end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Buesing</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1548</link>
		<dc:creator>Geoff Buesing</dc:creator>
		<pubDate>Fri, 16 Nov 2007 19:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1548</guid>
		<description>@weepy: agreed, push as much Javascript code as you can into functions that reside in script files in /public/javascripts, and then call these functions from document.ready and js.erb files.

You&#039;ll reap the benefits of browser caching with script files in public, and the code that&#039;s not cached (i.e, code embedded in the page, and in js.erb files) will read at a higher level.</description>
		<content:encoded><![CDATA[<p>@weepy: agreed, push as much Javascript code as you can into functions that reside in script files in /public/javascripts, and then call these functions from document.ready and js.erb files.</p>
<p>You&#8217;ll reap the benefits of browser caching with script files in public, and the code that&#8217;s not cached (i.e, code embedded in the page, and in js.erb files) will read at a higher level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Buesing</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1547</link>
		<dc:creator>Geoff Buesing</dc:creator>
		<pubDate>Fri, 16 Nov 2007 19:13:41 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1547</guid>
		<description>&lt;p&gt;@jean-sebastien: regarding setting request headers, I&#039;ve been  meaning to update my older post that gave those instructions -- I&#039;ve since discovered that adding the file extension (e.g., .js) to the url is an all-around better solution to request a specific format, if for no other reason than, it avoids issues with page caching and different mime types.&lt;/p&gt;
&lt;p&gt;So that I can add the correct file extension to a url parsed from the page, I came up with a javascript function that intelligently adds an extension to a url, respecting querystring params:&lt;/p&gt;
&lt;pre lang=&quot;javascript&quot;&gt;
function addFormatToURL(format, url) {
	var urlArray = url.split(&#039;?&#039;);
	// add extension to url, unless it&#039;s already there
	if ( urlArray[0].search(&#039;.&#039; + format + &#039;$&#039;) == -1 ) { urlArray[0] = urlArray[0] + &#039;.&#039; + format; }
	return urlArray.join(&#039;?&#039;);
}
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>@jean-sebastien: regarding setting request headers, I&#8217;ve been  meaning to update my older post that gave those instructions &#8212; I&#8217;ve since discovered that adding the file extension (e.g., .js) to the url is an all-around better solution to request a specific format, if for no other reason than, it avoids issues with page caching and different mime types.</p>
<p>So that I can add the correct file extension to a url parsed from the page, I came up with a javascript function that intelligently adds an extension to a url, respecting querystring params:</p>
<pre lang="javascript">
function addFormatToURL(format, url) {
	var urlArray = url.split('?');
	// add extension to url, unless it's already there
	if ( urlArray[0].search('.' + format + '$') == -1 ) { urlArray[0] = urlArray[0] + '.' + format; }
	return urlArray.join('?');
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: jean-sébastien</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1541</link>
		<dc:creator>jean-sébastien</dc:creator>
		<pubDate>Fri, 16 Nov 2007 03:26:56 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1541</guid>
		<description>Hi geoff, 
i&#039;m using rails 2.0 pre release. and when i launch an ajax request with query, it doesn&#039;t work : rails take it as html formating.
So i must add &#039;.js&#039; to my request to be considered as javascript.

i must precise that my ajax request seems to be well formatted (dataType: &#039;scr1pt&#039; beforeSend: function(xhr) {xhr.setRequestHeader(&quot;Accept&quot;, &quot;text/javascript&quot;)

can you give me your opinion?</description>
		<content:encoded><![CDATA[<p>Hi geoff,<br />
i&#8217;m using rails 2.0 pre release. and when i launch an ajax request with query, it doesn&#8217;t work : rails take it as html formating.<br />
So i must add &#8216;.js&#8217; to my request to be considered as javascript.</p>
<p>i must precise that my ajax request seems to be well formatted (dataType: &#8217;scr1pt&#8217; beforeSend: function(xhr) {xhr.setRequestHeader(&#8220;Accept&#8221;, &#8220;text/javascript&#8221;)</p>
<p>can you give me your opinion?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1517</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 13 Nov 2007 09:33:26 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1517</guid>
		<description>Wonderful.  Those little helpers from the MinusROR plugin really make this elegant.

Cheers.</description>
		<content:encoded><![CDATA[<p>Wonderful.  Those little helpers from the MinusROR plugin really make this elegant.</p>
<p>Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: weepy</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1501</link>
		<dc:creator>weepy</dc:creator>
		<pubDate>Mon, 12 Nov 2007 08:27:49 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1501</guid>
		<description>You should extract all common code out of the .js.erb into your public javascript files, and then just use the calls to these functions in the .js.erb. For example. 

=&gt; .js.erb
updateMyStuff()

=&gt; .js
updateMyStuff = function(x) {
  $(&#039;my_div&#039;).html(x);
}</description>
		<content:encoded><![CDATA[<p>You should extract all common code out of the .js.erb into your public javascript files, and then just use the calls to these functions in the .js.erb. For example. </p>
<p>=&gt; .js.erb<br />
updateMyStuff()</p>
<p>=&gt; .js<br />
updateMyStuff = function(x) {<br />
  $(&#8216;my_div&#8217;).html(x);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Branstrom</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1475</link>
		<dc:creator>Branstrom</dc:creator>
		<pubDate>Sat, 10 Nov 2007 10:42:33 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1475</guid>
		<description>Matt: First of all, that is not unique to this solution. It&#039;s the same with RJS.

It&#039;s a Good Thing to keep all JS and markup separate for the sake of easy maintenance and readability. Keep structure and behavior separate.

This stuff (JS + data ajaxed in on certain events) doesn&#039;t really add to the initial load time, which is the primary concern when talking about the number of HTTP requests. These .js.erb requests will add up if you&#039;ve got many of them, granted. Feel free to benchmark it...</description>
		<content:encoded><![CDATA[<p>Matt: First of all, that is not unique to this solution. It&#8217;s the same with RJS.</p>
<p>It&#8217;s a Good Thing to keep all JS and markup separate for the sake of easy maintenance and readability. Keep structure and behavior separate.</p>
<p>This stuff (JS + data ajaxed in on certain events) doesn&#8217;t really add to the initial load time, which is the primary concern when talking about the number of HTTP requests. These .js.erb requests will add up if you&#8217;ve got many of them, granted. Feel free to benchmark it&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1456</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 08 Nov 2007 23:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1456</guid>
		<description>This may be a really dumb concern. 

It appears you&#039;re suggesting that all view-specific JS be thrown into separate JS files instead of embedded in the HTML with script tags.  Isn&#039;t this in opposition to the standard best practice of reducing the number of HTTP requests?

More HTTP requests means longer load times and more work for the server.</description>
		<content:encoded><![CDATA[<p>This may be a really dumb concern. </p>
<p>It appears you&#8217;re suggesting that all view-specific JS be thrown into separate JS files instead of embedded in the HTML with script tags.  Isn&#8217;t this in opposition to the standard best practice of reducing the number of HTTP requests?</p>
<p>More HTTP requests means longer load times and more work for the server.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: weepy</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1453</link>
		<dc:creator>weepy</dc:creator>
		<pubDate>Thu, 08 Nov 2007 21:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1453</guid>
		<description>awesome stuff. 

How about rolling it all up into a nice little plugin. </description>
		<content:encoded><![CDATA[<p>awesome stuff. </p>
<p>How about rolling it all up into a nice little plugin.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeroen</title>
		<link>http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/comment-page-1/#comment-1452</link>
		<dc:creator>jeroen</dc:creator>
		<pubDate>Thu, 08 Nov 2007 19:26:41 +0000</pubDate>
		<guid isPermaLink="false">http://mad.ly/2007/11/02/javascript-embedded-ruby-templates-with-rails-out-of-the-box/#comment-1452</guid>
		<description>Nice! It would be nice to bundle this into a small plugin. I&#039;m not using rails 2 yet, but I think I&#039;ll be using this once it&#039;s out.</description>
		<content:encoded><![CDATA[<p>Nice! It would be nice to bundle this into a small plugin. I&#8217;m not using rails 2 yet, but I think I&#8217;ll be using this once it&#8217;s out.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
