Ask A Question


You’re not receiving notifications from this thread.

How Do I Search Against Records Saved In Memory, and Not the Database?

Steve Polito asked in Rails


I have an event that starts Jan 1, 2017 and repeats every day until Dec 31, 2017. If I search for an event (using ransack) that starts after Jan 1, 2017 no events will appear, because the only record saved to the database has a start date of Jan 1, 2017. The rest of the records are created in memory. However, if I search for an event that starts before Jan 1, 2017, all results render as expected.


I have a list of repeating events. The repeating events are created using ice_cube and recurring_select, along with the following method in my model.


def events_list(start)
    if recurring.empty?
    end_date = start.end_of_year
      schedule(start_time).occurrences(end_date).map do |date| id, title: title, start_time: date, club: club)


def all
      @q = Event.ransack(params[:q])
      @events = @q.result(distinct: true).order(start_time: :desc)
      @events_list = @events.flat_map{ |e| e.events_list(params.fetch(:start_date, }
      @events_list_paginated = @events_list.paginate(page: params[:page])
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.