hotwired / turbo-rails

Use Turbo in your Ruby on Rails app
https://turbo.hotwired.dev
MIT License
2.11k stars 327 forks source link

rendering turbo_stream templates badly possible outside controller and confusing file namings #455

Closed chmich closed 1 year ago

chmich commented 1 year ago

Hi

i tried to render turbo templates by a gem and there is no change to render a turbo_stream template by absoulute path.

What works

render template: 'layouts/my_template' #=> within the controller
render template: 'my_template' #=> within the controller

# naming
my_template.turbo_stream.erb
my_template.turbo_stream.haml

Not working

render file: Rails.root.join('app', 'views', 'articles', 'check_file.turbo_stream.erb')
render template: 'layouts/my_template' #=> from within a module that resides inside a gem

# naming
my_template.turbo_stream.html.erb
my_template.turbo_stream.html.haml

Strange

at a former project there was the opposit: i had to name my templates by .html.haml for make it working. Now setup a new project that didnt work, i had to name it .turbo_stream.haml for make it running.

Also, rendering from a absolute path tried to render the view within a layout. While layout by rendering from a relative path by default is true, from a absolute path, or to say by the file attribute ist should be false by default

Please fix

it would be a great help if turbo_stream templates could be rendered by a absolute path and please fix this super confusing file suffix handling. It should not matter if there is a .turbo_stream.html.erb or a .turbo_stream.erb or same in haml. I lost many days for finding that.

marcoroth commented 1 year ago

I don't think there's anything special within turbo-rails which would prevent/enable any of this. I think this either would need to be handled in Rails or in Haml itself.

marcoroth commented 1 year ago

The correct names for the templates would be

my_template.turbo_stream.erb
my_template.turbo_stream.haml

as you pointed out.

my_template.turbo_stream.html.erb
my_template.turbo_stream.html.haml

The names above will not work implicitly because turbo_stream and html are both formats. You either need to use one or the other.

chmich commented 1 year ago

thanks, @marcoroth, you're right! i created a new issue on rails

chmich commented 1 year ago

@marcoroth thanks it works, newly gem is running and it includes your gem: turbo_power. Thanks for that also! render_turbo_stream