I step outside of the world for a few days and things seem to break.
I can’t seem to find why the following isn’t replacing just the turbo_frame_tag on my page. The button_to is calling the method, but won’t work in the way I’m expecting. For some reason, if it works at all, it replaces the whole page and not just the content of the turbo_frame. And it doesn’t show start the video at the right time code. Any help you can provide would be greatly appreciated.
Button_to code:
<%= button_to changetime_video_path(time: key), method: :post, form: {data: {'turbo-frame': 'showvideo'}}, class: "text-sm text-left text-orange-500 hover:text-white" do %><%= value %><% end %>
changetime method
def changetime
# Designed to load the video at the timecode
time = params[:time]
@newtime = time.split(':').map(&:to_i).inject(0) { |a, b| a * 60 + b }
end
changetime.html.erb
<%= turbo_frame_tag "showvideo" do %>
<% if !@video.wis_slug.nil? %>
<div class="wistia_embed wistia_async_<%= @video.wis_slug %>"> </div>
<% else %>
<div class="aspect-w-16 aspect-h-9">
<iframe src="https://www.youtube.com/embed/<%= @video.youtube_slug %>?start=<%= @newtime %>&enablejsapi=1&rel=0&autoplay=1&modestbranding=1&cc_load_policy=0" allow="autoplay; accelerometer; gyroscope" frameborder="0" allowfullscreen></iframe>
</div>
<% end %>
<% end %>
UPDATE: OK. Using Chrome, when I Inspect, it seems to replace the whole page, but with the correct video timecode, but for some reason it’s not auto playing. When I turn off the Inspect mode, it auto plays. HOWEVER … it still seems to be loading the whole page?? I thought Hotwire stopped that and only did the part it needed. Or do I keep needing to put layout: false in my methods?
Whatever is happening is stopping it from working on mobiles or iPads etc
I really don’t understand why it’s calling the method but returning the whole page when I’ve told it to only look at the “showvideo” section of the page.
I’ve checked the HTML it’s generating, and that seems to be fine.
Isn’t it supposed to just return the HTML in the changetime.html.erb file?
Thanks in advance. This is driving me to drink!