How to use mutiple yields

In my layout, i have mutiple layouts.
Is there any way to reduce to a single line.Currently my layout likes
this

<%=yield :head%>

<%=yield :foot%>

<%=yield :bottom%>

How to call this in a single method

On 12 November 2011 04:38, Nike M. [email protected] wrote:

In my layout, i have mutiple layouts.
Is there any way to reduce to a single line.Currently my layout likes
this

If you really want to (though I don’t know why you would…)

<% [:head, :foot, :bottom].each do |to_yield| %><%=yield to_yield %>
<%end%>

Although strictly, that’s still three lines…

How about

<%=yield :head%><%=yield :foot%><%=yield :bottom%>

:wink:

How to call this in a single method

You could also move those three lines into a partial, and render that
with a single line in your layout.

On 12 November 2011 16:53, Rob B. [email protected]
wrote:

Or just:

<%= [ :head, :foot, :bottom ].map {|section| yield section } %>

Yes, of course, that’d work nicely.

On Nov 12, 2011, at 7:30 AM, Michael P. wrote:

Although strictly, that’s still three lines…

How about

<%=yield :head%><%=yield :foot%><%=yield :bottom%>

:wink:

Or just:

<%= [ :head, :foot, :bottom ].map {|section| yield section } %>

Though it makes be wonder how/why the associated content_for blocks
are not together already making this a bit moot.

-Rob

How to call this in a single method

You could also move those three lines into a partial, and render that
with a single line in your layout.

Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs