Turbo not streaming changes properly / window.Turbo is undefined
TaylorJonesTRT opened this issue · 3 comments
To begin I'm not sure if this is a turbo-rails 2.x.x issue or all around.
Whenever I attempt to have my rails app render a turbo_stream.replace, the browser instead of rendering the replacement is downloading the raw html file of the actual turbo_stream replacement.
I'm using old code from a few months back from when this was originally working (my gemfile.lock says I was on 1.5.0) back then with a new Rails app that was just scaffold-ed.
When attempting to dive into this and figure out the issue I did find out that window.Turbo is undefined in my console on the Rails app.
My controller code:
exercise_name = exercise_params[:name]
@exercise = Exercise.build(name: exercise_name, user_id: current_user.id)
if @exercise.save
update_exercise_list
else
render exercises_path, status: :unprocessable_entity
end
end
private
def exercise_params
params.require(:exercise).permit(:name, :personal_best)
end
def update_exercise_list
render turbo_stream: turbo_stream.replace('exercise_list',
partial: 'exercises/exercise_list',
locals: { exercises: current_user.exercises.order(name: :asc) })
end
My partial view that contains the turbo frame:
<ul class="mt-5">
<% exercises.each do |exercise| %>
<li>
<%= exercise.name %>
</li>
<% end %>
</ul>
<% end %>
The attached files are what my browser downloads
exercises.txt
exercises(15).txt
This still works properly in my old project but does not when I force my current project to use 1.5.0. In chrome it doesn't download a file but displays the raw html as text.
I have to do some back tracking but I was able to resolve this issue, don't believe it's anything in the package/gem itself.
@TaylorJonesTRT please close resolved issues to help maintainers and other developers looking at issues.