Search code examples
ruby-on-railsrubycoffeescriptmaxinfinity

RoR: Is there a value for infinite?


I am trying to set up a max_users method. I have two different software types, hardware and software, and I am trying to set hardware to 1, and software to unlimited (eventually the user will choose in a form field how many max users they want, but for now just unlimited.

Any help is much appreciated. Thank you in advance.

Here's my model code:

def set_max_users
  if max_users.nil?
    self.max_users = 1
  end
end

And my JS that I'm using to dynamically add form fields with cocoon(in case this would help at all):

$ ->
  check_to_hide_add_link = ->
    max_users = parseInt($("#asset_max_users").val(), 10)
    if $("#assets_users .nested-fields").length >= max_users
      $("#assets_users .links a").hide()
    else
      $("#assets_users .links a").show()

  $("#assets_users").bind "cocoon:after-insert", ->
    check_to_hide_add_link()

  $("#assets_users").bind "cocoon:after-remove", ->
    check_to_hide_add_link()

  check_to_hide_add_link()

Solution

  • Asked and answered here: How to express infinity in Ruby?

    but the short of it is:

    Float::INFINITY