I needed to do the same for the chart, where you could choose the period of the data that should be displayed.
So I introduced the CSS class “btn-group-radio” and used the following unobtrusive single-line javascript:
// application.js $(document).ready(function() { $('.btn-group-radio .btn').click(function() { $(this).addClass('active').siblings('.btn').removeClass('active'); }); });
And here is the HTML:
<!-- some arbitrary view --> <div class="btn-group btn-group-radio"> <%= link_to '1W', charts_path('1W'), class: 'btn btn-default active', remote: true %> <%= link_to '1M', charts_path('1M'), class: 'btn btn-default', remote: true %> <%= link_to '3M', charts_path('3M'), class: 'btn btn-default', remote: true %> <%= link_to '6M', charts_path('6M'), class: 'btn btn-default', remote: true %> <%= link_to '1Y', charts_path('1Y'), class: 'btn btn-default', remote: true %> <%= link_to 'All', charts_path('all'), class: 'btn btn-default', remote: true %> </div>
sled Oct 27 '13 at 21:34 2013-10-27 21:34
source share