Pry Flack wrote in post #1111699:
> Berlimioz wrote in post #1111694:
>
>> On the other hand, when you have this :
>>
>> <<-EOF
>>       <div class="accordion" id="#{@parent_id}"> <!-- first line -->
>>         #{yield self}
>>       </div> <!-- last line -->
>>     EOF
>>
>> the expression "yield self" will here return the return value of the
>> block
>> you pass. When you pass a block like this :
>
> Yes that's what I was trying to do. I found my mystake. I need to use an
> instance variable to build the output buffer. Here is a working ruby
> "prototype" https://gist.github.com/PryFlack/5732422
>
> Now I'm gonna have to bring this into my rails app and see how it goes
> because as I said yield self behaves differently inside an ERB template.
>
> Enjoy your week-end too !

Well I am failing miserably with this!

My latest attempt here: https://gist.github.com/PryFlack/5723324

Having so much difficulty with this I thought about going a different
way. I realized i could also do the following:

=====START=====
      <% parent_id = "myAccordion" %>

      <%= render layout: 'accordion', locals: { parent_id: parent_id }
do |parent| %>

        <%= render layout: 'accordion_element',
          locals: { target_id: "collapseRow1", title: "Row1",
            parent_id: parent_id, in_or_out: "in" } do %>

          <p>inside child1</p>
        <% end %>

        <%= render layout: 'accordion_element',
          locals: { target_id: "collapseRow2", title: "Row2",
            parent_id: parent_id, in_or_out: nil } do %>

          <p>inside child2</p>
        <% end %>

      <% end %>
=====END=====

However this is still pretty verbose. So this adds more complexity and
 it's pretty rigid (if I want to modify the rendering of the html
block, I have to modify my calls to render everywhere)

Also apart from creating an instance variable inside the erb template, I
don't see a good way to pass value in the nested rendered layout (other 
than repeating myself)

Has anybody got any good info on how to generate and abstract complex
html blocks ?

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/144ded550e06a42877650b9d08480891%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to