lundi 13 avril 2015

Check if yield is defined

I couldn't find a solution to this question.


Well, on my application.html.erb I defined a content space:



<%= yield :scripts %>


I have a view app.html.erb who use this space to put some contents:



<% content_for :scripts do %>
<script>
$(document).ready(function() {
app.init();
});
</script>
<% end %>


I would like to know if is possible check if yield :scripts exists on application.html.erb. If not I would like to print this part of code (inside content_for) on my app.html.erb view (sometimes this view was called by ajax so I need that these code come with the view).


Something like:



if :scripts.exists?
content_for :scripts do
...code...
end
else
...code...
end


Thank you!!


Obs: My Rails version is 3.2.21.


Aucun commentaire:

Enregistrer un commentaire