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.
Add a comment
|
1 Answer
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?}
1 Comment
Edito
Only possible after 10 minutes