1

I am doing some pagination and can do @next_images_to_paginate += 4 without a problem.

But @previous_images_to_paginate -= 4 doesn't because I can get negative numbers.

I can't use absolute because I want -1, -2 and -3 to be 0.

Something like:

((@previous_images_to_paginate -= 4) < 0) ? 0 : (@previous_images_to_paginate -= 4)

but I would like something less wordy.

The page being created is not appropriate for will_paginate, etc.

undur_gongor
  • 15,657
  • 5
  • 63
  • 75
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

1 Answers1

13

How about using the max function from an array

x = [x-4,0].max
undur_gongor
  • 15,657
  • 5
  • 63
  • 75
Rob Di Marco
  • 43,054
  • 9
  • 66
  • 56