i am using rails and mongo db as database simply i want to search I have a field name role Now i send the search item in
params[:role]
params[:name]
Now i have the model User now what could be my query to search the data in the User model like params[:name] I did like
@role = params[:role]
@name = params[:name]
@data = User.{where(:role => @role)}.where("description LIKE (?)",
"%# {@name}%").desc(:created_at).
excludes(:id => current_user.id)
Above query is just analysis. I mean to say it should like in therotical but i didnt get id.
Does this work? (from my head...)
@role = params[:role]
@name = params[:name]
@users = User.where(:role => @role)
@data = @users.where(users[:description].matches("%#{@name}%")).order("created_at desc").excludes(:id=> current_user.id)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.