开发者

searching and sorting with paginate_by_sql -- will_paginate

I am using paginate_by_sql for a model's function.

 def index

@refprobes = Refprobe.paginate_by_sql ["select * from ref_probe
                                      where RPR_OID in
                                (SELECT DISTINCT RPR_OID
                                FROM REF_PROBE
                                JOIN ISH_PROBE ON RPR_OID = PRB_MAPROBE
                                JOIN ISH_SUBMISSION ON PRB_SUBMISSION_FK = SUB_OID
                                JOIN SEC_USER_PI ON USP_PI_ID = SUB_PI_FK
                                WHERE U开发者_如何学运维SP_USER_FK = " + session[:user_id]+ ")"], :page => params[:page], :per_page => 10

end

I want to add search and sorting to the above.

How do i do that?

Many many thanks


I realize this is quite old, but just came across it.

I guess you could always do something like this:

sql = <your existing sql>     
order = " ORDER BY #{params[:order]}"    
sql_to_paginate = sql + order

The other option would be to rewrite the query using Rails' syntax and then you could use the .reorder() method.

Hope this helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜