Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
152 How to redirect from a form that is inside a turbo frame?
- Loading branch information
Showing
6 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
module ApplicationHelper | ||
def autoredirect(url) | ||
link = tag.a href: url, style: 'display: none', data: { controller: 'autoclick', turbo_cache: false } | ||
turbo_stream.append_all('body') { link } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module TurboStreamsHelper | ||
def advanced_redirect(url) | ||
turbo_stream_action_tag(:advanced_redirect, url: url) | ||
end | ||
end | ||
|
||
Turbo::Streams::TagBuilder.prepend(TurboStreamsHelper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
import "@hotwired/turbo-rails" | ||
import "controllers" | ||
|
||
import {Turbo} from "@hotwired/turbo-rails" | ||
|
||
// turbo_stream.action(:redirect, comments_path) | ||
Turbo.StreamActions.redirect = function() { | ||
Turbo.visit(this.target) | ||
} | ||
|
||
// turbo_stream.advanced_redirect(comments_path) | ||
Turbo.StreamActions.advanced_redirect = function() { | ||
let url = this.getAttribute('url') | ||
console.log(url) | ||
Turbo.visit(url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
connect() { | ||
this.element.click() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= turbo_stream.prepend 'body' do %> | ||
abc | ||
<%#= link_to 'redirect to something', comment_path(@comment), style: 'display: none;', data: { controller: 'autoclick' } %> | ||
<%#= link_to 'redirect to something', comments_path, style: 'display: none;', data: { controller: 'autoclick' } %> | ||
<% end %> |