Rails: using link_to to make a link without href

后端 未结 8 1839
情书的邮戳
情书的邮戳 2020-12-29 19:05

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

8条回答
  •  北海茫月
    2020-12-29 19:36

    <%= 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')
        }
      });
    }
    

提交回复
热议问题