codyc4321
codyc4321

Reputation: 9682

rails ERB template language construct for <%= vs <% compared with django templates

coming from Django I am wondering how rails people think about <%= %> vs <% %>

From what I see here <%= tag.title %> displays information that's already present like attributes of the obj, like the {{ }} in django, and <% %> always does stuff, like an each loop or if statement, like the {% %} in django.

If that statement fully accurate, or is there a finer line I missed? Thanks

Upvotes: 0

Views: 126

Answers (1)

thedanotto
thedanotto

Reputation: 7327

Yeah you've basically got it down.

<% %>

Will run ruby code without displaying it

<%= %>

Will display the information to the screen

<%# %>

Will comment out ruby code in your view

Here's just a simple example

<% @users.each do |user| %>
  <%= user.email %>
<% end %>

This question may help you as well.

Upvotes: 2

Related Questions