If I write something like:
<% if signed_in?.blank? %>
or <%= link_to "Sign Up", sign_up_path %>
What is the difference between the two signs of <%
and <%=
?
Why make it this way instead of using just one for simplicity?
When do I know I need to use <%
over <%=
?
%> is used to embed some java code within the main service() method of the JSP. It is executed during the rendering of the page. <%! ... %> is used to define code outside of the flow of the page, and therefore outside the main service() method.
h is just alias for html_escape. It is a utility method commonly used to escape html and javascript from user input forms.
2.2. By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.
What is a ERB file. ERB files contain source code written in a programming language of the same name. The ERB language is essentially a Ruby templating language. ERB files are saved in a plain text format which allows them to be opened in any text editing program.
<%=
puts the return value of the code inside to the page.
<%
just execute code.
Here is the good guide about ERB http://api.rubyonrails.org/classes/ActionView/Base.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With