vendredi 1 juillet 2016

Rails: Unknown column in SELECT statement

I'm trying to verify user login on a Rails app. The controller code looks like:

def create
  user = User.where(params[:session][:email]).first
  # user = User.where(:type=> 'User', :email => params[:session][:email])
  debugger
  if user and user.authenticate(params[:session][:password])
    session[:user_id] = user.id
    redirect_to admin_url
  else
    redirect_to login_url, alert: "Invalid user/password combination"
  end
end

Parameters are being correctly passed, but it's trying to search for a 'users' attribute in the users table. There isn't a users attr. The users table looks like this:

mysql> DESCRIBE users;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| userid     | int(11)      | YES  |     | NULL    |                |
| email      | varchar(255) | YES  |     | NULL    |                |
| password   | varchar(255) | YES  |     | NULL    |                |
| fname      | varchar(255) | YES  |     | NULL    |                |
| lname      | varchar(255) | YES  |     | NULL    |                |
| created_at | datetime     | NO   |     | NULL    |                |
| updated_at | datetime     | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Aucun commentaire:

Enregistrer un commentaire