lundi 19 février 2018

When use OR in ruby? [duplicate]

This question already has an answer here:

After setup the current_user with the standard session, would be great if the user log in with cookie or api token. so the utilization of the OR seems required.

def current_user
    token = User.find_by(cookies[:auth_token]) or params[:api_token] 
    @current_user ||= token if cookies[:auth_token]
  end

i've added the or against the find_by

SQLite3::SQLException: unrecognized token: "9C46LFbm3Mzn1K6iA4HwdQ": SELECT "users".* FROM "users" WHERE (9C46LFbm3Mzn1K6iA4HwdQ) LIMIT ?

and the db raised this exception, that seems not related with the function so my doubt is if OR can be used with find_by ir just with where?

Aucun commentaire:

Enregistrer un commentaire