SQL Like operator in ruby on rails

爷,独闯天下 提交于 2019-12-04 02:37:40

Try:

@studentname = Student.where("name LIKE :name1 AND city = :cityId1",
  {:name1 => "#{params[:name]}%", :cityId1 => params[:cityId]})

This is a rather dirty solution, but pure ARel cannot handle this case the way you desire. You might want to try the Sqeel gem.

Sandip Karanjekar

Try

@studentname = Student.where("name LIKE ? AND city = ?", "#{params[:name]}%", params[:cityId])

there is a error in your methods, it should be like this

  @studentname = Student.where("name = :name1 AND city = :cityId1",
     {:name1 => params[:name], :cityId1 => params[:cityId]})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!