javascript - How do you do some jQuery inside a ruby if/else loop in a Rails html.erb file? -


i have button present in html, default hidden css #comments_button{ display: none; }.

i want button appear if notice has comments. in _notice.html.erb:

<%= button_tag "comments", id: "comments_button" %>   <span>comments</span> <% end %>  <% if notice.comments.any? %>   *** jquery $("#comments_button").show(); *** <% end %> 

how call jquery inside ruby if/else loop?

please note, button should present in html can't this:

<% if notice.comments.any? %>   <%= button_tag "comments", id: "comments_button" %>     <span>comments</span>   <% end %> <% end %> 

you can insert script tag in erbs, e.g. following should work

<%= button_tag "comments", id: "comments_button" %>   <span>comments</span> <% end %>  <% if notice.comments.any? %>    <script>       $("#comments_button").show();    </script> <% end %> 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -