fixed sql query using where rails