Gugubaight Gugubaight - 2 months ago 19
Ruby Question

Rails 4: Use Operators within Loops

I am struggling with checking the param

user_id
. How can I change that from
=>
to something similar this operator:
!=


And fortunately how can I do the same with
<=
and
>=


- @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

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)