Search code examples
ruby-on-rails-3browser-history

How to change url in address bar?


I have a landing page with two tabs when i click on tabB I use js and update div

$.get("/users", function(data) {}); 

$('.userTable').html("<%= escape_javascript render(:file => 'users/index.html.erb') %> ");

How I can change the url in address bar also?? Every tab has function like create, edit which is also I do using ajax. How I can change url in address bar for create and update?? I check some railscast but none of them is talking about crud. Thanks a ton in advance for help.


Solution

  • You can use the history manipulation api:

    //Change address to http://www.test.com/page.php:
    history.pushState('', '', 'http://www.test.com/page.php');
    

    See How do I do awesome refreshless page changes like GitHub do? or https://github.com/blog/760-the-tree-slider