Ruby: tap not working? -


Write code for my application_controller To translate user input into queries, this works:

  result_set = model # ActiveRecord :: implementation of the base as a few classes. Contains (metric_template = & gt; [: group]) # Need to summarize this. Where (f) .order (sort_string) .limit (rows) .offset (pages -1) * rows)   

This does not work, because the method does not say where: result_set = model.includes (: Metric_template = & gt; [: group]) # There is a need to stop it. Tap {| O | O.where (f) if f} .order (sort_string) .limit (rows) .offset ((page-1) * rows)

I really like it. Tap () Why not work here? Is not it available as a class method? Can this be assured?

Appreciate any guidance.

It is that you want to (effectively):

  Result_set = models include (: metric_template = & gt; [: group]). # It is necessary to stop this order yet (sort_string). Border (rows). Offset (page-1) * rows) result_set = result_set.where (f) if f   

this is not actually a condition that calls to tap , Which is most useful for working on an item without changing the value in exchange for the method (due to reasons that SEP 2k has explained).

In addition, this is probably the best thing to do in this method model.

Comments