Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4, render a partial/layout with optional block within haml

I have created a haml-partial which I want to use as a default header. When rendering this out I optionally want to give it a block to replace a part of the default content.

I've tried multiple things:

render partial: "partial", capture: do
# Don't really know why I tried this, Syntax error ofcourse.

render partial: "partial" do
# 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.

render layout: "partial" do
# Works, but:

render layout: "partial"
# You invoked render but did not give any of :partial, :template, :inline, :file or :text option.
# So, it always needs the block

Any other options I don't know of?

like image 880
Tim Baas Avatar asked Oct 31 '13 14:10

Tim Baas


1 Answers

Use render layout: "" when you need a block.

Use render partial: "" when you don't use a block.

They both work with locals and look for a pre-underscored file.

like image 76
Tim Baas Avatar answered Sep 21 '22 20:09

Tim Baas