0

So I feel like this should be straightforward. I am using the react-rails gem to use some react in my rails app when needed. In this case, I am rendering a react_component form in the edit view. Once the update is complete (which takes place in react using axios), I want to use the rails controller to redirect to the index view which is not a react component. I would think a simple redirect to would work example:

redirect_to users_path, notice: 'Update successful.'

But when my update is completed, the redirect thinks it is a 'put' request and fails with 404

PUT http://localhost:3000/users 404 (Not Found)

Is it possible to redirect from the rails controller? If not, what is the work around?

EDIT: fixed type user_path to users_path

user15395591
  • 153
  • 1
  • 1
  • 7
  • http://localhost:3000/users is not the user_path, are you talking about redirect_to users_path? as you are using the Axios, maybe you can do the page redirect with window.location.replace – Feifei Xiong May 25 '21 at 07:01
  • @FeifeiXiong that is a typo. It should say users_path. I could do a redirect in the client but my hopes were to avoid this and use rails. – user15395591 May 25 '21 at 14:42
  • sorry for the late response, yes, you can do it, since you are responding a js request, you should use format.js – Feifei Xiong Jun 10 '21 at 05:15

0 Answers0