0
0

More than 3 years have passed since last update.

パーシャルで繰り返し処理

Posted at

教えていただいたことの備忘録として残します。

bar.html.erb
<%= render partial: 'foo', hoges: @hoges %>
_foo.html.erb
<% hoges.each do |hoge| %>
 <% hoge.name %>
 <% hoge.price %>
<% end %>

これでも動作確認はできましたが、以下のようにします。

bar.html.erb
<%= render partial: 'foo', collection: @hoges, as: 'hoge' %>
_foo.html.erb
 <% hoge.name %>
 <% hoge.price %>

こうすることで読み込み速度が向上します。
collectionオプションを使うと1回しか読み込まれないみたいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0