TL;DR I''d like to expand the convention that layouts named after the
current controller get loaded *instead of* the
default application.html.erb, by providing the possibility to get them
loaded *by *application.html.erb.
I just discovered that rails automatically looks for layouts named after
the current controller. So if I''m in example.com/projects/* and there
is a
layout named "projects.html.erb" rails renders that one instead of
"application.html.erb".
Problem is: if I created a layout for every resource there is, I had to
deal with a lot of overhead regarding html structure. That would, of
course, counteract the idea of the layout system in the first place. So
instead of doing that, I''d like to nest those templates. I could
achieve
that by using [1], but imho that''s not very convenient.
Maybe it''s possible to expand the convention explained above:
while surfing in /projects/*:
- if there is a layout named "projects.html.erb" it gets loaded
*instead
of* application.html.erb (as ever)
- if there is a layout named "_projects.html.erb" it gets
loaded *by*application.html.erb. _projects.html.erb provides the
resource-specific
template and renders the action-related views using <%= yield %>
That would allow for easy layout nesting and structures like
Basecamp''s
layout could be achieved easily:
|--- application.html.erb
\--- _projects.html.erb
\--- _todos.html.erb # depending on resource nesting in
routes.rb
\--- _discussions.html.erb
\--- _calendars.html.erb
Maybe I''m missing the forest for the trees here and stared too long at
my
screen to find a satisfying solution for my problem here, but currently
that sounds like a good idea to me. Any thoughts on that?
Chris
[1]
http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.