0

I am using rails 4.0 and I want to remove obtrusive javascript. I must be missing something, I have this link_to:

= link_to t('hide'),'#', :'data-hide-table'=>"#row_#{@result.id}", :class=>'hider'

In my model.js I have following code (I have also tried putting it inside application.js):

  $(document).ready(function() {
    $('.hider').click(function (event) {
      console.log("fsg");
      $(this).data("hide-table").hide();
      event.preventDefault();
    });
  });

However, nothing is being logged into console, and of course that I need to hide is not being hidden. Btw. everything works when I use:

= link_to_function t('hide'), "$('#row_#{@result.id}').hide()"
  • `link_to_function` in rails 4????? – Rajarshi Das Sep 11 '13 at 10:36
  • http://stackoverflow.com/questions/5063246/rails-3-status-of-link-to-function-method look at it – Rajarshi Das Sep 11 '13 at 10:36
  • 2 Rajarshi Das, link_to_function is deprecated and will not be supported since 4.1 and I want to remove it from my code, in my question it is mentioned just for illustration that it works using link_to_function, but thanks for your link – user2040438 Sep 11 '13 at 10:42
  • and btw. using :onclick, as suggested in posted link does not seem to be unobtrusive way of handling onclick event in rails – user2040438 Sep 11 '13 at 10:53
  • `:'data-hide-table'=>"#row_#{@result.id}"` what is it? – Rajarshi Das Sep 11 '13 at 10:53
  • `= link_to t('hide'),'#', :onclick => "$('#row_#{@result.id}').hide();"`...try this – Rajarshi Das Sep 11 '13 at 10:56
  • :'data-hide-table'=>"#row_#{@result.id}" is the way of giving parameters for event handling using jguery (at least according to this guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript), and sure I could use :onclick, but it still is not unobtrusive javascript that i would like to use – user2040438 Sep 11 '13 at 11:05

0 Answers0