You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sorry this is not actually an issue, but may help someone to avoid mistakes.
It is possible that most of find_each offenses found in views are false positives and fixing them will lead to errors, because find_each overrides the order, which is most likely set on the controller or somewhere else, maybe even in a default scope
Example:
%ul
- @cities.includes(:country).each do |city|
%li #{city} (#{city.country})
$ haml-lint
test.haml:2 [W] RuboCop: Rails/FindEach: Use `find_each` instead of `each`.
NOTES:
@cities.each does not report an issue, the problem is with AR clauses like where and includes
It may be not a best practice to use includes or where in views, but that would be a different issue
In this context, cities were probably been sorted in the controller or somewhere else. find_each will revert their order
For the moment I'm using
Rails/FindEach:
Exclude:
- '**/*.haml'
Maybe these Rails/* cops causing troubles should be documented somewhere, together with #443
What do you think?
The text was updated successfully, but these errors were encountered:
Hello,
sorry this is not actually an issue, but may help someone to avoid mistakes.
It is possible that most of
find_each
offenses found in views are false positives and fixing them will lead to errors, becausefind_each
overrides the order, which is most likely set on the controller or somewhere else, maybe even in a default scopeExample:
NOTES:
@cities.each
does not report an issue, the problem is with AR clauses likewhere
andincludes
includes
orwhere
in views, but that would be a different issueIn this context,
cities
were probably been sorted in the controller or somewhere else.find_each
will revert their orderFor the moment I'm using
Maybe these
Rails/*
cops causing troubles should be documented somewhere, together with #443What do you think?
The text was updated successfully, but these errors were encountered: