MarioV
MarioV

Reputation: 48

Why is this block not working on my ERB template

<%= render layout: "shared/some_template", 
      locals: {
               variable_value: true 
              } do %>
   <%= hidden_field_tag "ids[]", "ng-value": "sth.id" %>
<% end %>

The template on some template has some html and a yield call where the "hidden" field should go but it's not rendering it, it does render everything else inside the template, it just drops the hidden_field_tag part.

Any idea how can I solve this? it works on the HAML version when I tried it, but not on ERB, is that not available for ERB?

Upvotes: 0

Views: 421

Answers (1)

Phlip
Phlip

Reputation: 5343

You are passing a &block to render, which is doing nothing with it.

To pass a callback to a partial, build a lambda and put it in a local variable:

<%= 
  lamb = lambda{ hidden_field_tag 'ids[]', 'ng-value' => 'sth.id' }
  locals = { variable_value: true, callback: lamb }
  render layout: 'shared/some_template', locals: locals
 %>

Now inside the template call <%= callback.call %>.

(Note, BTW, that I used ' instead of ", because we are not using the special features of ". And note I introduced a local variable, locals, instead of creatively indenting the render call.)

Upvotes: 1

Related Questions