Rails render partial with block

前端 未结 5 1923
灰色年华
灰色年华 2020-12-04 06:35

I\'m trying to re-use an html component that i\'ve written that provides panel styling. Something like:

  
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 07:19

    You can use the capture helper, and even inline in the render call :

    <%= render 'my_partial',
               :locals => { :title => "Some Title" },
               :captured => capture { %>
        

    Here is some content to be rendered inside the partial

    <% } %>

    and in shared/panel:

    <%= title %>

    <%= captured %>

    which will produce:

    Some Title

    Here is some content to be rendered inside the partial

    See http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html

提交回复
热议问题