Part of the problem is that you are defining a class method called find_current and an instance method called filter_my_rows. As a rule, you define them both within the same field, and for collaboration.
Another thing is that you can do a lot of filtering that you need with a simple call to # Array # reject. For example:
@models = all.reject do |m| # This block is used to remove entries that do not qualify # by having this evaluate to true. !m.current end
You can do this with modulation by adding functions if necessary, but it can get complicated if you are not careful.
While you stated in your question that this is only necessary because of concerns that you cannot determine the relevance of a particular record before all records are downloaded from the database, this is usually a bad form, since you, you will probably reject a large amount of data that you encounter with the problem of obtaining and creating instances as models only to delete them immediately.
If possible, you should at least cache the received rows for the duration of the request so that you do not have to collect them all the time.
tadman
source share