Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the use of both <% and <%= in the views?

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 <%=?

like image 998
LearningRoR Avatar asked Jun 13 '12 13:06

LearningRoR


People also ask

What is the significance of <%! In JSP?

%> 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.

What does H in <%= h %> stand for in rails?

h is just alias for html_escape. It is a utility method commonly used to escape html and javascript from user input forms.

How can you tell Rails to render without a layout?

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?

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.


1 Answers

<%= 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

like image 85
Flexoid Avatar answered Oct 26 '22 10:10

Flexoid