William K. Hatch Jr. wrote:
> Hello all,
> 
> I've got an action that's somewhat heavy (slow) that returns ...js.erb.

You should probably fix that.  Dynamically generated JS is usually a 
design problem IMHO.

> The action completes fine, and I can see the results in firebug in the 
> console, but the javascript isn't being executed, on the production 
> (more like production test) box. It works fine locally in development 
> env, and if I copy and paste the returned stuff from the firebug console 
> response it will execute just fine.  Here's the js erb:

And here are my suggestions for doing it with static JS, which might 
perhaps solve your problem.

> 
> $("#<%...@element_id%>").fadeOut();
> $("#<%...@element_id%>").hide(100);

If you don't know the element ID in advance, just assign it a known 
class name when the HTML is generated.  Then you can do 
$(".fade").fadeOut();.

> $("#FirstTheme").append("<%= escape_javascript(render(:partial => 'tag', 
> :locals=>{:entity_id=>@entity_id, :theme_id=>@theme_id, 
> :entity=>@entity, :element_id=>@element_id, :parent_id=>@parent_id, 
> :tag=>@tag})) %>");

That's awful!  The right way to do this is to have something like the 
following in your .html.erb file (or rather, equivalent Haml), where 
your CSS defines .hidden {display: none}:

<div class="hidden" id="firstThemeContent">
  <%= render :partial => 'tag', :all => 'the', :other => 'stuff' %>
</div>

then in the static JS

$("#FirstTheme").append($("#firstThemeContent").innerHTML)

Again, no js.erb necessary.

> $("#ObsList").html("<%= 
> escape_javascript(render(:partial=>'explore/observation', 
> :collection=>@observations))%>");

Use the same technique as above.

This should clean up your JavaScript considerably and may help you 
isolate the problem, if it does not get rid of it entirely.

Also, most people use lowercase (either dashed-lower-case or 
lowerCamelCase) for their DOM IDs.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to