1

I am using @registers.delete_if { |r| r.location_id != @location_id && @location_id.present?} to filter the registers so that only the ones with the chosen location_id are kept, if anything was chosen at least. The thing is that using the @location_id.present? works just fine but checking if the id's are the same doesn't. If I check hardcoded with a number like this: r.location_id != 5 it does work.

1 Answer 1

2

Try it like this :

@registers.delete_if { |r| r.location_id != @location_id.to_i && @location_id.present?}

But I think to do it better you should do it like :

@registers.delete_if { |r| r.location_id != @location_id.to_i if @location_id.present?}
Sign up to request clarification or add additional context in comments.

1 Comment

Only possible after 10 minutes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.