I am trying to do something like this,
# toggle.turbo_stream.erb
<%= turbo_stream.morph "completed_todos_section" do %>
<%= render partial: "some_model/completed_todos", locals: {todos: @completed_todos } %>
<% end %>
and it results in
Showing app/views/todos/toggle.turbo_stream.erb where line #3 raised:
undefined method `morph' for #<Turbo::Streams::TagBuilder:0x00007f314f0d5908 @view_context=#<ActionView::Base:0x000000000529e0>>
So, we don’t have a helper method for morphing right now?
We do have a morph
helper method. So why isn’t it working?
# Morph the <tt>target</tt> in the dom with either the <tt>content</tt> passed in or a rendering result determined
# by the <tt>rendering</tt> keyword arguments, the content in the block, or the rendering of the target as a record. Examples:
#
# <%= turbo_stream.morph "clearance_5", "<div id='clearance_5'>Morph the dom target identified by clearance_5</div>" %>
# <%= turbo_stream.morph clearance %>
# <%= turbo_stream.morph clearance, partial: "clearances/clearance", locals: { title: "Hello" } %>
# <%= turbo_stream.morph "clearance_5" do %>
# <div id='clearance_5'>Morph the dom target identified by clearance_5</div>
# <% end %>
def morph(target, content = nil, **rendering, &block)
action :morph, target, content, **rendering, &block
end
# Morph the <tt>targets</tt> in the dom with either the <tt>content</tt> passed in or a rendering result determined
# by the <tt>rendering</tt> keyword arguments, the content in the block, or the rendering of the targets as a record. Examples:
#
# <%= turbo_stream.morph_all ".clearance_item", "<div class='clearance_item'>Morph the dom target identified by the class clearance_item</div>" %>
# <%= turbo_stream.morph_all clearance %>
# <%= turbo_stream.morph_all clearance, partial: "clearances/clearance", locals: { title: "Hello" } %>
# <%= turbo_stream.morph_all ".clearance_item" do %>
1 Like
Nevermind, it was added 3 days ago.
To resolve this temporarily,
Add this to your Gemfile
:
gem 'turbo-rails', git: 'https://github.com/hotwired/turbo-rails.git', branch: 'main'
Run:
bundle install
2 Likes