简体   繁体   中英

ruby on rails check if value exist in array always returns true

I am trying to check if a set pset(aka problem set) exist in an array in order to display the correct page but the following code always returns true...

  def c
    allowed_psets = [1]
    pset_id = 12323

    if allowed_psets.include?(pset_id)
        //do something here
    else
        render_404//error
    end
  end

do i miss something here?

working code:

  def c

    allowed_psets = [
        1
    ]

    pset_id = params[:pset_id]

    if allowed_psets.include?(pset_id.to_i)
        #do something here
    else
        render_404#error
    end

  end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM