Yield :layout, add extra content at controller level

Hi,

Could someone point me in the right direction for specifying content at
the controller level so that I could use something similar to “yield
:left_nav_content” as well as “yield :layout” in my layouts?

I know I can specifiy this content in my view using something like:

<% content_for(“left_nav_content”) do %>

Some Menu Options


<% end %>

However I would need to repeat this in each view for a particular
controller. Any pointers on where to start looking at the
ActionController source to understand how this mechanism works greatly
received.

Andrew.

Andrew,

If you need to repeat a content block in numerous views I would
recommend simply creating another layout for those actions to use.

Hope this helps,
Zack

Zack C. wrote:

Andrew,

If you need to repeat a content block in numerous views I would
recommend simply creating another layout for those actions to use.

Hope this helps,
Zack

Hi Zack,

This was the path I was taking but found that there was a lot of
repeated code as each controller only required a different left hand
menu.

Ideally I would like to be able to stack layouts, which unfortunately it
not a feature I am aware of. I have taken this opportunity to learn more
about the plugins and am seeing if there is any way I could augment the
ActionController to give an easily reversed temporary solution.

I’m still learning ruby so get a bit lost when trying to follow some of
the rails ActionController and ActionView relationships.

All I really need is to pass the name of a partial to the layout so that
it can insert it in the left hand column. Unless a plugin exists that
does something similar?

It just seems such a waste to duplicate a bunch of layouts just for the
difference of a single section. I suppose I could pass in the menu via a
partial using the content_for helper in each view but it’s similarly
anti-DRY given multiple actions for a controller.

Andrew.

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