<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">JB, Mark, Artan,<br>
<br>
Thanks so much for the advice - much appreciated.<br>
<br>
JB, regarding the jasmine fixtures issue, is the approach you
blogged about back in 2010 still the best approach?<br>
<br>
<a class="moz-txt-link-freetext"
href="http://pivotallabs.com/javascriptspecs-bind-reality/">http://pivotallabs.com/javascriptspecs-bind-reality/</a>
<br>
<br>
Many thanks in advance<br>
CHEERS> SAM<br>
<br>
On 23/07/2013 01:39, JB Steadman wrote:<br>
</div>
<blockquote
cite="mid:CAK5aQA5Q3ymPM3YXK7hG7rQZimWjZo-xegdj0-jz-tB-SjLJEg@mail.gmail.com"
type="cite">
<div dir="ltr">If you decide to try this approach, consider
setting the body class using a method exposed by your
controllers, like this:
<div><br>
</div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><font face="courier new, monospace"><body
class="<%= body_class %>"></font></div>
<div><font face="courier new, monospace"><br>
</font></div>
</blockquote>
<font face="arial, helvetica, sans-serif">The default
implementation can return </font><font face="courier new,
monospace">"#{controller_name} #{action_name}"</font><font
face="arial, helvetica, sans-serif">, while subclasses have
fine-grained, situation-specific control. For example, if
there's a form error creating a new order, forcing a re-render
of the </font><font face="courier new, monospace">new</font><font
face="arial, helvetica, sans-serif"> template, you probably
don't want "orders create" as the body class, but rather
"orders new". You can also easily add other classes aside from
just controller name and action name.</font></div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Tue, Jul 23, 2013 at 1:13 AM, JB
Steadman <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:jb@pivotallabs.com" target="_blank">jb@pivotallabs.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div class="im">On Mon, Jul 22, 2013 at 8:25 PM, Sam
Joseph <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:tansaku@gmail.com" target="_blank">tansaku@gmail.com</a>></span>
wrote:<br>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
2) similarly: if i have N distinct pages in my app
and each has its own quite distinct JS bits, given
that the best practice is to combine all the JS
and load it all at once and cache it (asset
pipeline), is there a best practice for
'inhibiting' setup functions ($(document).ready())
that don't correspond to the 'current' page? (ie,
your setup function might be trying to bind the
'#foo' element, but that element only exists on a
particular page; do you let the setup function
silently fail, or do you arrange to only run that
particular setup function if you're on the page
containing #foo, or do you condition the function
so that it gracefuly fails in the absence of
#foo?)<br>
<br>
</blockquote>
<div><br>
</div>
</div>
<div>It can be helpful in many ways to encode the
controller name and action name as classes in a
high-level element such as <font face="courier new,
monospace"><body></font>, giving you, for
example:</div>
<div><br>
</div>
</div>
</div>
<blockquote style="margin:0 0 0
40px;border:none;padding:0px">
<div class="gmail_extra">
<div class="gmail_quote">
<div><font face="courier new, monospace"><body
class='orders new'></font></div>
<div><br>
</div>
</div>
</div>
</blockquote>
You can use this to scope css as well as javascript.
Continuing your example, you might have:
<div><font face="courier new, monospace"><br>
</font></div>
<blockquote style="margin:0 0 0
40px;border:none;padding:0px">
<div><font face="courier new, monospace">$(document).ready(function()
{</font></div>
</blockquote>
<blockquote style="margin:0 0 0
40px;border:none;padding:0px">
<div><font face="courier new, monospace">
$('body.orders.new #foo').bind(...);</font></div>
</blockquote>
<blockquote style="margin:0 0 0
40px;border:none;padding:0px">
<div><font face="courier new, monospace">});</font></div>
<div><font face="courier new, monospace"><br>
</font></div>
</blockquote>
<font face="arial, helvetica, sans-serif">On pages aside
from orders new, the function does not fail per se, but
it has no effect. You can observe your app to determine
whether accumulation of such functions has any
meaningful performance impact.</font><span
style="font-family:'courier new',monospace"> </span><br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Technical blog: <a class="moz-txt-link-freetext" href="http://linklens.blogspot.com">http://linklens.blogspot.com</a></pre>
</body>
</html>