William K. Hatch Jr. wrote:
> On Sep 24, 2010, at 12:27 PM, Marnen Laibow-Koser wrote:
> 
>> 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.
> 
> What??? It's the response for an ajax request; I don't understand what 
> you're saying here. How else would I take data driven content and insert 
> it into the dom?

I know it's an Ajax response.  Your Ajax responses should generally be 
data (HTML or JSON) to be processed on the client side, not code.

>>> 
>>> $("#<%...@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();.
> 
> Again, this isn't when the html is initially generated.

Doesn't matter in the least.

> I think I wasn't 
> clear: this is an ajax request; not an html request.

An Ajax request *is* (or can be) an HTML request; it's really no 
different than a non-Ajax request from your server's point of view.

>> <div class="hidden" id="firstThemeContent">
>>  <%= render :partial => 'tag', :all => 'the', :other => 'stuff' %>
>> </div>
>> 
>> then in the static JS
>> 
>> $("#FirstTheme").append($("#firstThemeContent").innerHTML)
> 
> Again, this content wouldn't exist at the time of the page load, so it's 
> not possible for it to be there in the first place.

Irrelevant.  Your client-side static JS should fire the Ajax request, 
then process the returned HTML fragment or JSON packet to put it into 
the DOM.

>> 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.
> 
> well, the shop i'm doing it for uses camel case caps for the id's, and 
> lowercase dashed on class names.
> 
> Sorry, but I think you're completely missing the point, probably because 
> I didn't explain it well.

As far as I can tell, I am not missing the point at all.  I hate to say 
it, but I think you are, in that you seem to be under a misapprehension 
as to how to use Ajax efficiently.

What do you think I'm missing?

> 
> All of this works, has worked fine, in development. The issue is it's 
> not getting rendered by the browser even though it is being returned to 
> the browser, in production, on the server.  So, request comes in, gets 
> processed, javascript gets returned to the browser, and if in 
> development, the appropriate elements update and content is inserted. If 
> in production, request comes in, gets processed, javascript gets 
> returned to the browser, and nothing happens.

So stop returning JS to the browser!  That's not the way to do Ajax well 
IMHO.  See my suggestions above.

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