I want to use
link_to 'Cancel', edit_project_path(@project, url_options)
to cancel the edit and go back to the edit page.
I use jQuery UI Tabs for a tabbed edit page. Each tab has it's own form and submit/cancel buttons.
When I click a Cancel link I want to go back to the active tab. So I set
url_options = {:anchor => active_tab_id}
The problem is: the page doesn't reload because of the anchor.
Adding data-no-turbolink
does not help:
link_to 'Cancel', edit_project_path(@project, url_options), :data => {:no_turbolink => true}
If you put # inside the href like <a href="#"></a> then the link will not refresh or reload when clicked.
window. location. href method returns/loads the current url. So we can use it to reload/refresh the page in javascript.
link_to is a Rails built in helper that helps generate an anchor tag.
try using<%=link_to("Cancel", edit_project_path(@project, url_options), method: :get)%>
this helped me better
The only way to do it is with javascript.
Add custom data attribute to the link:
link_to 'Cancel', edit_project_path(@project, url_options), :data => { :reload => true }
Then put this javascript somewhere, for example in app/javascripts/reload_hash.js
$(function(){
$('a[data-reload="true"').on('click', function(e) {
window.location = $(e.target).attr('href');
window.location.reload(true);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With