问题描述:

when i use the where method,

users.where('id = ?', params[:id])

then i got what i want.

if i want to do upward statement using hash, i can do this.

users.where(:id => params[:id])

then i can get exactly same things


but now,

users.where('nickname like ?', '%' + params[:nickname] + '%')

then, how can i do exactly same thing using hash as a parameter of where method?

网友答案:

You cannot use Hash syntax in this case. The best way is to do what you are doing right now. But you can shorten the query a little bit using interpolation

where('nickname like ?', "%#{ params[:nickname] }%")
相关阅读:
Top