Should we provide shorthand methods or be more DSL-like with more magic?
Closed this issue · 0 comments
andrewculver commented
For example, this is my current new.html.erb
:
<%= render 'account/shared/page' do |p| %>
<% p.content_for :title, t('.section') %>
<% p.content_for :body do %>
<%= render 'account/shared/box', divider: true do |p| %>
<% p.content_for :title, t('.header') %>
<% p.content_for :description, t('.description') %>
<% p.content_for :body do %>
<%= render 'form', tangible_thing: @tangible_thing %>
<% end %>
<% end %>
<% end %>
<% end %>
This is great because it plays on the natural language of Rails partials, but...
Potential Suggestion 1
Is there a place for a shorthand like this when invoking a nice partial?
<%= render 'account/shared/page' do |p| %>
<% p.cf :title, t('.section') %>
<% p.cf :body do %>
<%= render 'account/shared/box', divider: true do |p| %>
<% p.cf :title, t('.header') %>
<% p.cf :description, t('.description') %>
<% p.cf :body do %>
<%= render 'form', tangible_thing: @tangible_thing %>
<% end %>
<% end %>
<% end %>
<% end %>
This isn't un-Railsy, given how often content_for
is invoked. I mean, we have t
as an example of this sort of shorthand in Rails.
Potential Suggestion 2
Is it ugly/confusing/undesirable to go full magic like this? Reminds me a little bit of FactoryBot's syntax/DSL.
<%= render 'account/shared/page' do |p| %>
<% p.title t('.section') %>
<% p.body do %>
<%= render 'account/shared/box', divider: true do |p| %>
<% p.title t('.header') %>
<% p.description t('.description') %>
<% p.body do %>
<%= render 'form', tangible_thing: @tangible_thing %>
<% end %>
<% end %>
<% end %>
<% end %>