开发者

appending to content_for in rails

We are currently in the process of refactoring our site and we have decided to just go with one js library (jquery). Problem is, due to time constraint, we can only do so much so at the moment, we have to make them coexist.

This is easy since we have jquery's no conflict method, so I can just declare jquery then do the no conflict thing and then add prototype like so:

<%= javascript_include_tag "jquery" %>

<%= yield :jquery %>

<%= javascript_include_tag "prototype", "effects", "dragdrop", "controls", "lowpro", "neo", "filter", "slider", "calendar", "application", 'alerts'  %>

I then just call content_for(:jquery) whenever I need to add a specific jquery js file(this has the no conflict function) on the partial that needs it. So no problem there.

Problem is when you include 2 partials with different jquery files. Only one of them gets called since a content_for jquery is already called, it won't be called anymore(so lets say in a.rhtml, i added a.js and in b.rhtml i added b.js, only a.js will be included)

One solution would be to just include everything in one master js file but that would be difficult to maintain since every function is there etc. Is there a way so I can just 开发者_如何学Pythonappend to content_for when it already has been called?

I just checked the api:

http://apidock.com/rails/v2.3.8/ActionView/Helpers/CaptureHelper/content_for

it seems content_for actually APPENDS. But what happens to mine is it just doesn't append/clear out. It just completely ignores the second content_for call


Check out Jammit. You just define your various sets of files in assets.yml and then Jammit will package them up and generate minified and gzipped versions of those files for deployment. It's very easy to use, and you can keep functionality in multiple files and then just let Jammit package it up. This improves your client render speed, too, as it reduces HTTP connection overhead, and that single master file is easily cached, resulting in a snappy user experience.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜