Skip to content

Commit b9b87fc

Browse files
Document the turbo_frame_tag helper with multiple arguments (#329)
1 parent d4e26fe commit b9b87fc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/helpers/turbo/frames_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ module Turbo::FramesHelper
2323
# <div>My tray frame!</div>
2424
# <% end %>
2525
# # => <turbo-frame id="tray"><div>My tray frame!</div></turbo-frame>
26+
#
27+
# The `turbo_frame_tag` helper will convert the arguments it receives to their
28+
# `dom_id` if applicable to easily generate unique ids for Turbo Frames:
29+
#
30+
# <%= turbo_frame_tag(Article.find(1)) %>
31+
# # => <turbo-frame id="article_1"></turbo-frame>
32+
#
33+
# <%= turbo_frame_tag(Article.find(1), "comments") %>
34+
# # => <turbo-frame id="article_1_comments"></turbo-frame>
35+
#
36+
# <%= turbo_frame_tag(Article.find(1), Comment.new) %>
37+
# # => <turbo-frame id="article_1_new_comment"></turbo-frame>
2638
def turbo_frame_tag(*ids, src: nil, target: nil, **attributes, &block)
2739
id = ids.map { |id| id.respond_to?(:to_key) ? dom_id(id) : id }.join("_")
2840
src = url_for(src) if src.present?

0 commit comments

Comments
 (0)