Это должно быть легко, но я застрял ... Так что я использую Rails # 3 с Mongoid и хочу динамически строить запрос, который будет зависеть от переданных параметров и , а затем выполнить find(). Что-то вродеMongoid dynamic query
def select_posts
query = :all # pseudo-code here
if (params.has_key?(:author))
query += where(:author => params[:author]) # this is pseudo-code again
end
if (params.has_key?(:post_date))
query += where(:create_date => params[:post_date]) # stay with me
end
@post_bodies = []
Post.find(query).each do |post| # last one
@post_bodies << post.body
end
respond_to do |format|
format.html
format.json { render :json => @post_bodies }
end
end
ок, спасибо большое – xaxa
Привет я сделал, как этот запроса = '' Params [: событие] .each сделать | ключ, значение | query + = "{# {key}: # {value.to_s}}," if value.present? end events = Event.or (query) Но он не работает в MONGOID ... можете ли вы помочь –