ben@blackwolfstudios.co.uk
Joined
Activity
Posted in Custom Turbo Stream Actions Discussion
Hi Neil, I left the pins as stated above and eventually found a nice simple way of using the Turbo
object created via import '@hotwired/turbo-rails'
:
Turbo.StreamActions.redirect = function () {
const url = this.getAttribute('url') || '/'
Turbo.visit(url, { frame: '_top', action: 'advance' })
}
To round it out we created a quick helper as well:
module TurboStreams::RedirectHelper
def redirect(url)
turbo_stream_action_tag("redirect", url: url)
end
end
Turbo::Streams::TagBuilder.prepend(TurboStreams::RedirectHelper)
render turbo_stream: turbo_stream.redirect(root_url)
(it's essentially the same solution as in the link you posted)
Posted in Custom Turbo Stream Actions Discussion
I see you're importing from @hotwired/turbo
I have Rails 7 set up with importmaps so have the pin pin '@hotwired/turbo-rails', to: 'turbo.min.js'
however trying import { StreamActions } from '@hotwired/turbo-rails'
just results in the error: Uncaught SyntaxError: The requested module '@hotwired/turbo-rails' does not provide an export named 'StreamActions'
I've seen multiple different ways of solving the problem and even using something like turbo-power but what would be the recommended way of setting up the pins/imports/etc for a simple example like the console_log custom action?