Reputation: 1720
how i can search by 2 field in Rails 4
I'm trying to use this commands but it all not work with me
@user=User.by_username_and_password(params[:username],params[:password])
session[:user_user][email protected]
Also trying ton use this
@user=User.where(:user=>params[:username]).where(:pass=>params[:password])
session[:user_name][email protected]
so how in Rails 4 i can search by 2 or 3 fields ???
Upvotes: 0
Views: 216
Reputation: 1127
You can use this code.
User.where("username = ? AND password = ?", params[:username], params[:password))
Upvotes: 0
Reputation: 44685
User.find_by(username: params[:username], password: params[:password])
Upvotes: 2
Reputation: 6568
You should use this way
User.where(username: params[:username],password: params[:password]).first
or
User.find_by(username: params[:username],password: params[:password])
Where username and password are the columns in your table.
Upvotes: 1