尝试在 Controller 中插入简单的if
条件后出现此错误:
def index
if params[:query].present?
@blog_posts = BlogPost.search(params[:query])
else
@blog_posts = BlogPost.all
end
end
最佳答案
取决于模型的设置方式。正如Tire README所说,Mongoid的ID有点时髦,您可能必须自己定义to_indexed_json
:
def to_indexed_json
self.as_json
end
关于ruby-on-rails - BSON::InvalidObjectId非法ObjectId格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067528/