<div dir="ltr">I also have used the classes on `body` element, as it gives quite a good context, especially for hiding/showing elements on specific pages.<div><br></div><div>As for the JS, I wouldn't fail the jQuery objects silently, as you may create many of these unnecessarily. Even though they fail, if you have cached them, they still occupy memory. I'd instantiate the page specific JS classes in their respective pages. This way, you still load the JS all at once via the asset pipeline, but use as much browser memory as needed by the page.</div>
<div><br></div><div>Best,</div><div>Artan</div><div><a href="http://lugolabs.com">lugolabs.com</a><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 23 July 2013 01:39, JB Steadman <span dir="ltr"><<a 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">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="HOEnZb"><div class="h5">
<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 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>On Mon, Jul 22, 2013 at 8:25 PM, Sam Joseph <span dir="ltr"><<a href="mailto:tansaku@gmail.com" target="_blank">tansaku@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote">
<div>
<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>
</div></div><br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br></div>