dieuhd
dieuhd

Reputation: 1326

What is '<%%' in ERB in Rails?

I have bean seen code of scaffold in rails. I found

<%% breadcrumb_add "<%= plural_table_name.capitalize %>", <%= plural_table_name %>_path %>
<%%= render 'form' %>

https://github.com/rails/rails/blob/3fcc0ca99107fa57110421b392f5854555f17fe2/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb

What is <%% and how to use?

Upvotes: 3

Views: 148

Answers (1)

matt
matt

Reputation: 79813

<%% in Erb produces a literal <% in the output. You can use it if you want the output of your template to also be Erb, which is what is happening in the Rails example you link to.

In your code, the output will be something like (if the variable plural_table_name is things):

<% breadcrumb_add "Things", thing_path %>
<%= render 'form' %>

which itself is Erb.

Upvotes: 1

Related Questions