3
Rails 5.1 之後的 tag helper
source link: https://blog.niclin.tw/2018/12/26/rails-5.1-%E4%B9%8B%E5%BE%8C%E7%9A%84-tag-helper/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Nic Lin's Blog
喜歡在地上滾的工程師
用 rails 生 HTML 以往都是用 content tag
content_tag(:div, , class: "home")
<div class="home">
</div>
現在新的寫法直接用 tag 就可以了
<%= tag.div class: 'home' do %>
Welcome to Home!
<% end %>
<div class="home">
Welcome to Home!
</div>
不過目前 content_tag 和 tag 都還在共存的,未來不確定會不會移除舊的 syntax, 不過新的寫起來確實直覺多也少打點字就是了 XD
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK