thoughtbot / superglue

A productive library for Classic Rails, React and Redux
https://thoughtbot.github.io/superglue/
MIT License
327 stars 8 forks source link

Add comment to `*.html.erb` files that it is possible to dedup the number of these nearly empty files. #67

Open jho406 opened 2 weeks ago

jho406 commented 2 weeks ago

The superglue generator generates a foobar.html.erb for each action, the examples also show usage like this, but its actually easy to dedup these files as they can get overwhelming. We just put them in application for example, instead of posts/index.html.erb, we put them in application/index.html.erb, that will make rails lookup that template higher in the lookup path.

To make this work, we'd need the following in the application controller

  def render(...)
    @active_template_name = _normalize_render(...)[:template]
    super(...)
  end

then change modify the foobar.html.erb files with

<% initial_state = controller.render_to_string(@active_template_name, formats: [:json], locals: local_assigns, layout: true) %>

I think we should

  1. Add a comment inside these generators
  2. Or generate the usual index.html.erb, show.html.erb, edit.html.erb, new.html.erb for the users when running rails superglue:install:web.

Or both!