如果我理解正确,这就是你想要的:
def index
@m = Mymodel.ransack(params[:q])
@mymodels = @m.result.page(param[:page]).where(user: current_user)
end
不过,为了直接回答您的问题,您可以将其转换为SQL字符串,但您无法(或将很难)使用
current_user
def index
@m = Mymodel.ransack(params[:q])
sql = @m.result.page(param[:page]).to_sql
@mymodels = Mymodel.find_by_sql(sql, current_user)
# the line just above won't work immediately because you'll need to
# modify the `sql` variable manually by inserting the `?` that you'll
# need to map that to the `current_user` that you passed as an argument
end