1

I have a controller action: create which is responding to json format and html.

respond_to do |format|
  if @pr.save
    format.html {redirect_to(some_path)}
    format.json {render json: @pr, status: :ok}
  else
    format.html {}
    format.json {}
  end
end

So from a angular service I send a post request to this action, if it is successful I would like to redirect the user to some_path in my server log I see that redirect bing made, but the page is not changing.

How can I fix this? I am using turbo links as well so I would like not loading all the files again.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
John
  • 634
  • 8
  • 29

2 Answers2

1

If you are using Turbolinks you can do:

  1. Set a location in your controller:

    format.json {render json: @pr, status: :ok, location: some_path}

  2. Get the location from your header response in js:

    header('Location')

  3. Use Turbolinks visit:

    Turbolinks.visit(header('Location'));

And now you are not loading the assets.

alexsmn
  • 1,736
  • 11
  • 18
0

You should have a route where you want to redirect your user. Then In controller You can call the page

if( <Your Condition true/false> )
   $location.path('/dashboard');

remember you should have added dependency $location in your controller Or you can take a look here :

How to integrate Rails views with angularjs ng-view?

Community
  • 1
  • 1
SSR
  • 6,398
  • 4
  • 34
  • 50