What is the status of the link_to_function
Javascript helper in Rails? I read, including in this stackoverflow question, that it was deprecated in Rails 3.0, th
Building on Elias Baixas answer... I had to change it a bit to get it to work if this helps anyone... I had to add eval
and preventDefault
(I'm pretty terrible at JS fwiw)
link_to fa_icon('info-circle'),
'#',
data: {
on: :click,
call: 'channel_info',
args: Array('some data').to_json
}
function channel_info(a){
console.log(a)
}
//clean implementation of link_to_function
$(function(){
$('[data-on][data-call][data-args]').each(function(d){
try{
$(this).on( $(this).data('on'), function(event){
console.log($(this).data('args'));
window[$(this).data('call')].apply(window,eval($(this).data('args')));
event.preventDefault();
})
} catch(e) {
if(typeof(console) != 'undefined' && typeof(console.log === 'function'))
console.log(e);
}
});
})