Gugubaight Gugubaight - 11 months ago 74
Ruby Question

Rails 4: Use Operators within Loops

I am struggling with checking the param

. How can I change that from
to something similar this operator:

And fortunately how can I do the same with

- @jobsforyou.where(:is_finished => false, :is_active => true, :user_id => current_user, :sort <= 2).limit(10).each do |job|

The code-example gives an error.

Answer Source

For not you can directly do this

@jobsforyou.where.not(user_id: current_user)

For <= and >= you can use something similar to this

@jobsforyou.where("sort < ?", 3)