How can I use the link_to
helper to make a link without an href
attribute? I want to make a link exclusively for a javascript action, I don\'t want
Set the href to:
javascript:void(0)
This will let you have a link that clicking it does nothing, doesn't reload the page, and doesn't move the page up to the top.
<%= link_to '+ Add Make', 'javascript:void(0)', id: 'add-make', onclick: 'addMake()' %>
and then your jQuery:
function addMake() {
$.ajax({
url: '/dealers',
type: 'GET',
dataType: 'script',
success: function (data) {
console.log('it was successful')
$('.add-make').hide();
},
error: function (data) {
console.log('it was error')
}
});
}