Pawel Osiczko


220 Experience
2 Lessons Completed
0 Questions Solved


Posted in Recurring events with the ice_cube gem Discussion

Hi Chris!

Thank you for the episode. It was very educational. 8-) Ross Kaffenberger (@rossta) has a neat gem called Montrose ( similar to/inspired by ice_cube which models recurrence quite nicely as well.

I am stuck in the ice_cube world though trying to solve the following problem: My event model needs to be searchable/order-able. Since I did not want to reinvent the wheel, I ended up with datatables implementation. I created a nice JSON endpoint which produces events. I was cruising along with implementation, until I got to the actual search part. The JSON endpoint returns data which is ordered/searched via chained AR calls, something like:

def fetch_events
  search_string = []
  %w[name description city country state zipcode].each do |term|
    search_string << "#{ term } ILIKE :search"

  events ="#{sort_column} #{sort_direction}")
  events =
  events = events.where(search_string.join(' OR '), search: "%#{params[:search][:value]}%")

Soooo, it seems that if I want to include recurring events in the JSON endpoint, I should inject Event#calendar_events in the code above. One could, do that at the end, however, that wouldn't jive with sorting part. Not sure if one can try to do it early in the chain, becase, well, AR.

Would you, or anybody elase, have a clever idea how to handle that?

Thank you,


Posted in Recurring events with the ice_cube gem Discussion


Make sure you don't have old event data stored in the event table as you move through the excercise. Also, as Chris Seelus pointed out, latest recurring select does parse string null and makes it a valid rule.

Maybe put a guard to call super(nil) like so?

def recurring=(value)
    if value != "null" && RecurringSelect.is_valid_rule?(value)

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.