Helper method là Ruby method available trong view/template để tạo HTML tags và link.
erb
<%# link_to: tạo <a> tag %>
<%= link_to "Xem bài viết", post_path(@post), class: "btn" %>
<%= link_to "Xóa", post_path(@post), method: :delete, data: { confirm: "Chắc chưa?" } %>
<%# form_with: tạo form (RESTful-aware) %>
<%= form_with model: @post do |f| %>
<%= f.text_field :title %>
<%= f.submit "Lưu" %>
<% end %>form_with model: @post tự biết dùng POST /posts (tạo mới) hay PATCH /posts/:id (cập nhật) dựa vào @post.persisted?.
Từ Rails 5.1+ form_with thay thế form_for và form_tag.
A helper method is a Ruby method available in views/templates for generating HTML tags and links.
erb
<%# link_to: generates an <a> tag %>
<%= link_to "View Post", post_path(@post), class: "btn" %>
<%= link_to "Delete", post_path(@post), method: :delete, data: { confirm: "Sure?" } %>
<%# form_with: generates a form (RESTful-aware) %>
<%= form_with model: @post do |f| %>
<%= f.text_field :title %>
<%= f.submit "Save" %>
<% end %>form_with model: @post automatically knows to use POST /posts (create) or PATCH /posts/:id (update) based on @post.persisted?.
From Rails 5.1+ form_with replaces both form_for and form_tag.