Wordica
Wordica

Reputation: 2595

rails link_to with remote => true and jquery on click

I have simple question. I use rails link_to like this:

link_to 'sometxt', some_path(item), :class=>'fancybox button-click', :remote => true

and my question - is it right, to put jQuery on click event for this link ?

$('.button-click').on('click',function(){
    //some action
});

or it isn't good solution to have link_to with remote and jQuery on click event for one link?

What I want is to append loading gif when user click on link and fancybox showLoading doesn't work good for me so I'm trying other way to put preloader.

Upvotes: 4

Views: 2320

Answers (1)

Richard Peck
Richard Peck

Reputation: 76784

Good question!!

I'm not sure about overriding the click event (I'm sure it will be fine to bind twice, but I've not got any references)

--

Ajax

In regards to calling a preloader, you'll want to use one of the ajax hooks that Rails UJS provides:

#app/assets/javascripts/application.js
$(".button_click").on("ajax:beforeSend", function(){
    // preloader load
}).on("ajax:complete", function(){
    //preloader hide
});

enter image description here

This will be what you need

Upvotes: 4

Related Questions