code improved and working on rails search