Difference between “<%=” and “<%” when mixing ruby with html?

后端 未结 2 461
再見小時候
再見小時候 2021-01-28 05:28

I\'m learning Rails, and i\'m doing a exercise which i have to mix some html with ruby in a view file.

What is the main difference between \" <%= #code %> \" and \" &

2条回答
  •  清歌不尽
    2021-01-28 05:28

    <%= something which you would like to have displayed in your view %>
    <% something you would like to have hidden, 
    (or something which doesn't display anything in the view) such as a
     conditional statement %>
    
    <% if @post.nil? %>
        <%= render "nilNotify" %>
    <% else %>
        <%= @post.content %>
    <% end %>
    

提交回复
热议问题