This article uses Ruby 2.6.5 installed on macOS Catalina 10.15.6. When I write a helper method in a view file, I make a mistake depending on whether or not I add <%%> = at the moment, so I wrote it as a memorandum.
--Use this when you don't want to output __ in the view file. --For example, when conditional branching such as __if statement __ or iterative processing of __each statement __.
#if statement
<% if @name == 'hoge' %>
<% end %>
#each statement
<% @books.each do |book| %>
<% end %>
--Use this when you want to output the process described in the view file __.
<%= book.title %>
<%=form_with model: @user, url: user_registration_path, class: 'registration-main', local: true do |f| %>
<% end %>
<%= f.label :email %>
<%= render 'shared/error_messages' %>
Roughly speaking, __ <% =%> is overwhelmingly more __. In short, conditional branching such as __if and iterative processing such as each are not marked with = __, and processing that outputs to other screens may be added.
Recommended Posts