[RUBY] [Rails] [Memo] When to add = to <%%> and when not

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.

For <%%>

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

For <% =%>

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

Summary

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

[Rails] [Memo] When to add = to <%%> and when not
[Rails] Add column to devise
Library not loaded when trying to upgrade the version of ruby and rails s
What to check when rails db: migration does not pass
[Rails] How to add new pages
[Rails] Add strong parameters to devise
Add Not null constraint after Rails
How to solve the problem when the value is not sent when the form is disabled in rails and sent
[Rails] Add a confirmation screen and a completion screen to devise membership registration.
[Rails] What to do when rails s does not respond or does not stop
[Caution !!] Precautions when converting Rails devise and view files to haml
[Rails] I want to add data to Params when transitioning with link_to
[Rails] Annotate is not executed when migrating
Install Webpacker and Yarn to run Rails
How to resolve errors when installing Rails 5.1.3
Add spring boot and gradle to eclipse
[Rails 6] cocoon_ Add id and data attributes to the form to be added
[Rails] How to create a table, add a column, and change the column type
[Personal memo] Summary of stumbling blocks when deploying Rails apps to AWS
How to deal with FATAL: role "admin0" does not exist and PG :: ConnectionBad: FATAL: role "admin0" does not exist when executing rails db: create
Add binding.pry (rails)
[Rails] Add page nation to table [For beginners]
Rails and FormData
How to add / remove Ruby on Rails columns
Add a tag function to Rails. Use acts-as-taggable-on
What to do when rails db: seed does not reflect in the database
A memo when fumbling and developing using JavaFX
A memo to simply create a form using only HTML and CSS in Rails 6
[Rails] Bootstrap form-control does not apply to date_select
How to conditionally add html.erb class in Rails
How to build API with GraphQL and Rails
What to do when debugging "Source not found"
[Rails] Added in devise: username not added to database
[Rails] How to get success and error messages
Rails scope anti-patterns and how to eliminate them
Introducing what I made when I wanted to add a header and footer to RecyclerView
Check when created_at, datetime, etc. are not saved in Japan time in Docker and Rails
[In team development] Error when moving to another member's branch and doing rails s [Rails]
Implement a reservation system using Rails and simple calendar! Let's add validation to datetime!
[Ruby on rails + Mysql] Data migration procedure memo when switching from heroku to AWS
What to do when JSF tags do not become HTML
Rails "Not Null Constraint" and "Validation (presence: true)" Note
Change date and time to Japanese notation in Rails
How to add characters to display when using link_to method
[Rails] About error resolution when installing devise and activeadmin
What to do when rails creates a 〇〇 2.rb file
An introductory book to read when you start Rails
How to remove Ubuntu when dual booting Windows and Ubuntu
[Java] When var should be used and when it should not be used
[Java] [XML signature] Add prefix and ID to Signature tag
[Rails] How to edit and customize devise view and controller
[Rails] Create sitemap using sitemap_generator and deploy to GAE
[Rails 6] Add images to seed files (using Active Storage)
Extension to add up / down button and finish button to UIToolBar
(Ruby on Rails6) How to create models and tables
A memo to check when you try to use Lombok
When the server does not start with rails s
Try to implement tagging function using rails and js
Add files to jar files
Rails valid? And invalid?
How to write Rails