Ruby on Rails : Where not to use find_each

If you have arranged rows of data then you dont use find_each in views

@alerts = @user.alerts.order(updated_at: :desc)

# In views

<% @alerts.find_each do |alert| %
# This will pick data as in default order
# This may throw some Warning like
# Scoped order and limit are ignored, it's forced to be batch order and batch size

so, this should be like this

@alerts = @user.alerts.order(updated_at: :desc)

# In views

<% @alerts.each do |alert| %>
  <h2> Alert </h2>

<% end %>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s