Search code examples
ruby-on-railsrubyreactjsreact-rails

How to redirect to a ruby on rails controller that renders a react rails page


I have a button on my homepage that redirects to my controller: redirect_to edit_user_path(user, track: "homepage")

I can see that the redirect works correctly because if I throw a pry inside the controller it'll freeze.

The edit action inside my users_controller renders a react page. I am using the react rails gem.

When I visit the users/:id/edit page it works properly but for whatever reason when I go thru the redirect it doesn't load properly.

# edit.html.erb
`<%= react_component("App", @data) %>`
# users_controller#edit
# GET users/:id/edit
def edit
  @tracking = params[:track] if params[:track].present?
  @data = {name: "steve", age: 33, track: @tracking}
end

It almost looks like all of the props are missing because the react developer tools says: "waiting for roots to load..."


Solution

  • Turns out it was a timing issue. The link I was using had turbolinks enabled. When I changed turbolinks to be false everything worked as expected.