I'm upgrading an app from rails 5.2 to 6.1.7, as well as upgrading ruby from 2.6.10 to 3.0.5. Now all of the <%= render "partial_name" %> blocks in the erb view files are broken and throwing the error undefined method safe_append= for {:add_to_stack=>true}:Hash with the hint: safe_append= is being called on a add_to_stack object, which might not be the type of object you were expecting. This appears to be a deprecated ActionView::StreamingBuffer method. I did ensure that actionview has also been updated to 6.1.7, and I'm also not seeing any streaming buffer breaking changes in Rails 6 or 6.1. I don't see any related issues online anywhere. Anyone know what could be causing this?
Rails 5 to Rails 6 upgrade breaks partial rendering
458 Views Asked by Ando AtThere are 3 best solutions below
On
Upgrade to ruby version 3.x is ok.
I faced with same issue. Please check my case at: https://stackoverflow.com/a/75995680/3510489
On
I am also seeing this error when I use Ruby 3.0 on an app that was upgraded from Rails 6.0 to 6.1.
In Rails, ActionView::Template#render has this signature:]
def render(view, locals, buffer = ActionView::OutputBuffer.new, add_to_stack: true, &block)
and it is being called by a line in ActionView::PartialRenderer like this:
content = template.render(view, locals, add_to_stack: !block) do |*name|
view._layout_for(*name, &block)
end
and I think what is happening is that the keyword variable add_to_stack: !block is being treated as a Hash and given to the positional variable buffer which isn't using the default for some reason. This makes sense with the change in Ruby version because the treatment of these keyword/positional variables are changing. But I don't understand what I need to do to fix it.
If I revert to Ruby 2.7.8 it works fine, and I thought Rails 6.1 was supposed to support Ruby 3.0.
To officially answer my own question, this seems to have been too large of an upgrade to undertake. I broke this task up into smaller pieces and first upgraded to ruby
2.7.7and rails6.0.6.1and was able to get things going.