Why can't I nest a piece in a link_to block in Rails?

I saw a lot of posts about this, and even the documentation says that if you do

<%= link_to(result) do %> html-content-here <% end %> 

Then you get a tag with html content inside

However, when I do this

 <%= link_to(result) do %> <%= render :partial => 'campings/inSelection', :locals => { :result => result } %> <% end %> 

My link and partial are present, but I get something like this instead

 <a href="link"></a> partial's-content-here 

What is clearly not what I want, is it impossible?

This is my partial content:

  <div class="campingInHighlights"> <% imgUrl = result.photo1.blank? ? "/assets/camping_defaut.png" : "http://applicampings.francecom.com/photos/fiches/liste/#{result.photo1}" %> <%= image_tag imgUrl, class:"photo" %> <h3><%= link_to result.nom.to_s.downcase.capitalize, result %></h3> <p><%= result.ville.to_s.downcase.capitalize %> (<%= result.departement.code %>)</p> <div class="stars"> <% result.nbetoile.times do %> <%= image_tag "/assets/star.png", class: "star" %> <% end %> </div> </div> 

EDIT: Thus, it turns out that the problem is with the link tags contained in my partial part, in the partial there can be none of them, regardless of whether they were created manually or using the link_to function. Can someone explain what is going on here?

+4
source share
1 answer

Try replacing the <%= render.. tag with <% render.. (no = ) so that the render block returns partial text, but does not display it.

+2
source

Source: https://habr.com/ru/post/1435286/


All Articles