andrenth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-May-04 17:58 UTC
Avoiding unnecessary queries in javascript/erb views
Hello
I have a js view, say, things/index.js.erb that looks like this:
$(''my-stuff'').update("<%= escape_javascript(render
:partial =>
''shared/thing'', :collection => @things) %>");
Effect.toggle(''my-stuff'', ''slide'');
The idea is that the div with id ''my-stuff'' will slide down
and show
the collection when a certain link is clicked, and it''ll slide up if
clicked again. The problem is that on the second click, the file is
parsed again by erb, which results in a query being made to the
database to fetch the @things collection. This is unnecessry because
the content is already displayed and is now being hidden from the
user.
Is there any way to detect that situation and avoid that extra query?
Thanks,
Andre
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.