Pawel Osiczko

Joined

220 Experience
2 Lessons Completed
0 Questions Solved

Activity

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 (https://rossta.net/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"
  end

  events = Event.active.order("#{sort_column} #{sort_direction}")
  events = event.page(page).per(per_page)
  events = events.where(search_string.join(' OR '), search: "%#{params[:search][:value]}%")
end

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,

Pawel

Posted in Recurring events with the ice_cube gem Discussion

@Jeff:

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)
      super(RecurringSelect.dirty_hash_to_rule(value).to_hash)
    else
      super(nil)
    end
end