I've been doing some edits to an output when working with some records and i've ran into a problem where the sorting option no longer is working.
Initially with how things were created when I would do a @record.class the output was Record::ActiveRecord_Relation < ActiveRecord::Relation
However now after making my changes the class has changed. So now when I run a @record.class the output is Array < Object.
I think this is the root reason why i've ran into this problem.
My code is
@q = @records.search(params[:q])
@records = @q.result(distinct: true).select { |k,_v| k[:disabled] }
@records = @records.order("records.updated_at desc").page(params[:page] || 1).per(params[:per] || 30)
The error I am getting is NoMethodError: undefined methodorder' for #`
Now i've tried to workout around this by
@records = @records.sort_by("records.updated_at desc")
@records = @records.paginate.page(params[:page] || 1).per(params[:per] || 30)
However the error with the first line of my solution is @records = @records.sort_by("records.updated_at desc") I'm not able to get past that line in case there is an error with my paginate solution.
If anyone could take a look, I would really appreciate it!
searchmethod is coming from (and if you wrote it, the code).selectto select certain records (which loads all record from the database) instead of usingwhereand make only load matching records from the database? That would be much faster.