0

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.

regmiprem
  • 735
  • 2
  • 14
  • 41

1 Answers1

1

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)
Hugo Logmans
  • 2,202
  • 1
  • 19
  • 14
  • what is users here? I dont understand. and (:description) is the field name of users collection? – regmiprem Oct 10 '12 at 04:12
  • `users[:description].matches("%#{@name}%")` is the AREL-version of `"description LIKE (?)"`. I took those names from your commands, you you should know what they actually stand for :) – Hugo Logmans Oct 11 '12 at 09:20
  • If i want to match with other field also like field :email :address with @ name then what should i do? – regmiprem Oct 11 '12 at 12:23