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.

2

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

what is users here? I dont understand. and (:description) is the field name of users collection?
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 :)
If i want to match with other field also like field :email :address with @ name then what should i do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.