0

我使用 rails 和 mongo db 作为数据库只是我想搜索我有一个字段名称角色现在我将搜索项发送到

params[:role]
params[:name]

现在我有了模型 User 现在我可以查询什么来搜索 User 模型中的数据,例如我喜欢的 params[:name]

 @role = params[:role]
    @name = params[:name] 
     @data = User.{where(:role => @role)}.where("description LIKE (?)",
    "%#   {@name}%").desc(:created_at).
    excludes(:id    => current_user.id)

以上查询只是分析。我的意思是说它应该像在理论中,但我没有得到 id。

4

1 回答 1

1

这行得通吗?(从我的脑海中......)

 @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)
于 2012-10-09T14:01:18.850 回答