extra option for javascript_include_tag (:unique => true) for removing duplicate sources


I’ve created a small patch wherein I’ve added an extra parameter to the ‘javascript_include_tag’ (:unique => true) which will remove duplicate sources.

The reason for this is you can define javascript_expansion per functionality, not so much per group of sources. If so, you could end up with duplicate sources.

Imagine these 2 expansions:

:robber => [‘bank’, ‘robber’]

:banker => [‘bank’, ‘banker’]

the normal behavoir would expand to these sources:

calling javascript_include_tag :robber, :banker

javascript_include_tag_unique.patch (5.03 KB)

Is there a case where you *wouldn't* want to pass unique: true?


I think it would be better to always make them unique :). Can you
modify your patch to do that?

By the way, have you create the ticket?

I have created this option instead making it the default behavior because:

  • I didn’t want to change the existing tests as perhaps people still want to include whatever they want without having rails altering their logic/way of working. Perhaps making it default true with the option to set it to false.

I haven’t created a ticket yet, will do so.

Having it as an option which enable by default would be great. Please create a ticket so we can look at the patch.

Thank you :slight_smile:

ticket created here https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5876

I will change the patch to make :unique => true the default behaviour.



I’ve updated my patch to make this behavior the default one. https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5876

looking forward to your remarks/suggestions