Loop in Ruby on Rails html.erb file

后端 未结 3 591
梦毁少年i
梦毁少年i 2021-02-05 01:43

everybody I\'m brand new with Ruby on Rails and I need to understand something. I have an instance variable (@users) and I need to loop over it inside an html.erb file a limitat

3条回答
  •  Happy的楠姐
    2021-02-05 02:19

    Why don't you limit the users?

    <%= @users.limit(10).each do |user| %>
     ...
    <%end%>
    

    That'd still use ActiveRecord so you get the benefit of AR functions. You can also do a number of things too such as:

    @users.first(10) or @users.last(10)

提交回复
热议问题