Reputation: 634
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.
Upvotes: 1
Views: 60
Reputation: 6438
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?
Upvotes: 0
Reputation: 1746
If you are using Turbolinks you can do:
Set a location in your controller:
format.json {render json: @pr, status: :ok, location: some_path}
Get the location from your header response in js:
header('Location')
Use Turbolinks visit:
Turbolinks.visit(header('Location'));
And now you are not loading the assets.
Upvotes: 1