Ruby on rails - Insert a render inside an html tag

1

How do I add a render inside an HTML tag?

For example, this works here ok :

<%= render :partial => "feed/new_card", :locals => {
      :main_image => image_tag('feed/new_badge.jpg')
    } %>

<div><%= main_image %></div>

But I would like to do something like this:

<%= render :partial => "feed/new_card", :locals => {
      :main_image => <%= render feed/new_album %>
    } %>

<div><%= main_image %></div>

Is it possible? Because this is giving error here = /

Thank you.

    
asked by anonymous 29.12.2015 / 18:42

1 answer

1

In your controller:

@main_image = render_to_string(partial: 'feed/new_album')

In your view:

<%= render :partial => "feed/new_card", :locals => {
  :main_image => @main_image.html_safe
} %>

But be careful render_to_string is heavier than rendering, if used too much can cause slowness. Explain a little better what you are trying to do, because this code you showed to me does not make much sense and there should be a more effective way to solve your problem.

    
05.01.2016 / 17:27