Modifying a SQL query for use with 'will_paginate' in Ruby -


I have the following SQL query that I use to get some lines from a MySQL database:

  SELECT code_ver, the result from the MasterState, where the date & gt; = DATE_SUB (CURDATE (), INTERVAL 90 days) Order by DESC;   

This query gives me data from the last 90 days. Now I want to display 10 days of data at once in my html.erb page (view). I know that paging can be calculated using 'will_pignet' and 'camineri' gems. But I'm not sure how to ask the database with some of the above mentioned conditions.

Can anyone help me with the code here?

It is such that you can create it in ActiveRecord:

  Mastertest.where ('date' =? ', Time.Now-90 ("Code_ver, Results")   

From here, you can either either chain or fighter Methods, or if you want, do your roll. You can roll the question in class system if you use a lot of it:

  class Mastertest def self.last_90_days where ('Date' =? ', Time.now - 90 DAS). Order (' Date DESC '). Select ("Code_V , Result ") end ## Here is an example of a simple page: def self.page (page, per page) limit (per page) .offet ((page - 1) * Per_page) end-end Mastertest.last_90_days.page (1 , 20) # = & gt; [...]    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -