0

I've created a rails project and then integrated react with it using react_on_rails gem. I've made one component and placed it inside my new.html.erb using react_component helper method. Whenever this erb view renders I get the react component and after filling in the fields the component sends a POST request to todos#create path and the create action after saving the fields redirect to todos#show because of redirect_to @todo. The problem is that the show.html.erb is not rendered automatically as before. It gets returned in the response with the React component present inside.

  1. How do I render the view rendered in the response using a standard way?
  2. Is there any way to handle this situation without using react-router and using only rails defined routes.
Julien Rousé
  • 1,115
  • 1
  • 15
  • 30

1 Answers1

0

Most probably, your component sends the POST request using fetch, or ajax, instead of relying on the native behaviour of the form rendered by your React component.

You have a couple of options:

  1. Submit the form natively, this way the redirect will actually redirect.
  2. Have the server send a JSON response that the React component handles to update itself.
Matthieu Libeer
  • 2,286
  • 1
  • 12
  • 16