schoettl
schoettl

Reputation: 360

rails - link_to same page but with anchor -> no reload

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}

Upvotes: 6

Views: 6355

Answers (2)

santhosh kumar
santhosh kumar

Reputation: 153

try using
<%=link_to("Cancel", edit_project_path(@project, url_options), method: :get)%> this helped me better

Upvotes: 13

Alex Ponomarev
Alex Ponomarev

Reputation: 945

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);
        });
    });

Upvotes: 6

Related Questions