简体   繁体   中英

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 USP_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM