New Discussion

Notifications

You’re not receiving notifications from this thread.

Recurring events with the ice_cube gem Discussion

47
General

On my app I use a Event and a EventTrans model so for each time a event occurs we can have a record with info and other stuff. So for the Calendar we display the First event with the recurrent on the fly and each time the event pass we save it as a record or if we need to move only on recurrent we create it as a event transaction.

My only problem is the time it takes to check if a recurrent is create as event_trans or not for calendar view.

For some reason the simple_calendar gem messed with a bunch of the CSS on my site (e.g. all my links now have a black background on hover, etc.). Any hints on how to avoid this?

simple_calendar doesn't include any CSS for the links, so it must come from somewhere else. It only has some optional CSS for styling the calendar, but not links.

Sounds like you may have created a scaffold and the scaffold.css file is styling your links.

Thanks for a good demo for IceCube! I've been looking for this functionality to use it in one of my pet projects, but ended up with implementing something like this using cron format to represent recurrent event rules, and parse-cron gem to parse it. But now I'll try to switch to IceCube. I like the hash format it uses. It look less cryptic than crontab. Thanks for a good tip :)

Jorg Dominguez Jorg Dominguez

Waiting for the next episode!!!
You are great!

Really enjoying this series. Curious to when the next episode will be for exceptions etc?

Hey Josh, looks like I forgot to put the video in the series. You can find the episode here: https://gorails.com/episode...

Hi, thanks for the tutorial I found it very helpful. I wondered if you had any thoughts on the best way to query recurring events that have been serialised using the recurring gem? The issue I'm running into is if an individual who has not created the original calendar events wanted to search several calendars (created by other users) for free slots at given times the serialiser method then seems to become more complex than if we'd created individual discrete events. For example if you wanted to share calendars between different users. Would be interested to know your thoughts on this. Thanks

Depends on what you're trying to accomplish (like everything right? lol). What kind of search are you trying to pull off?

Shawn Nigel Rebello Shawn Nigel Rebello

Thanks a lot for this !

Has anyone gotten recurring_select to work on rails 5.2?? I keep getting a wrong number of attributes error no matter what I try to pass it.
Seems like it only occurs on Rails 5.2.rc2.. I'm not sure why though.
Looks like there was a change in the value method of the FormBuilder Base class. I changed it to not pass de object around anymore on a fork, but this would make the gem not work with previous versions... anyways, I'll leave the link here in case anyone is in need of a quick fix. https://github.com/gafemoyano/recurring_select
Good work! Looks like this probably changed somewhat recently then. The gem sure hasn't been updated for quite a while so it's surprising other things haven't broken!

Hello Chris, thank you so much for putting this leson together.
I followed it step by step and everything worked fine, that is until something got mistrerously broken and now I cannot seem to know what it is or how to put it back together.

Coould you please take a look to the issue I posted on github and let me know your thoughts?

https://github.com/GetJobber/recurring_select/issues/123

Best

OO

Thanks Chris, very helpful as always :-)

As RecurringSelect.is_valid_rule?('null') is true, I had to change the recurring=(value) method.

We did you change? I am getting the error "undefined method `to_hash' for nil:NilClass" And I was wondering if that could be the issue.

@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

Cool. Thanks for the tips!

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

I am using ice-cube gem for recurring.
Condition:
I have a form which allows user to select datetime for recurring.
Now I want to schedule and run a background job based on user frequncy.
Like if the frequncy is daily hten that job should run daily. How can I achieve this using ice-cube gem.

Any suggestions on how to handle searching the database for overlapping events when creating a new event?

With all the recurring info in the serialized column it seems there is no way to leave the heavy lifting to the database, and instead we need to iterate all events, find their recurring time slots, and compare. Is there any other solution?

Yeah, there's not a real easy way when the schedules are dynamically generated.

I've installed the gem exactly as the video says, however <%= form.select_recurring :recurring, nil, allow_blank: true %> throws an error "wrong number of arguments (given 1, expected 0)"

It's as if the gem hasn't installed and can't find the form helper.
Does anyone know where to go from here?

I'm using:
rails 6.0.1

And installing the gem like so:
gem 'recurring_select', github: "RundownApp/recurring_select"

I've also run bundle with no issues.

Out of curiosity, I created a new rails app exactly as Chris has here and I am getting the same error :(

Any help would be greatly appreciated :) Cheers guys

As was mentioned in the video, github: "RundownApp/recurring_select" was a fork for rails5. If you're having issues, try https://github.com/GetJobber/recurring_select which has been updated for rails 6

Hi Chris. This episode was exactly what I was looking for, thank you.
I've followed a few of your tutorials now and find them great.

I have been trying to figure out a way of marking individual instances of a recurring task as complete.
Has anyone tried/succeeded with this?

Thank you for sharing this video! I am having a really tough time with my application. When I go to create a recurring event, the javascript is not coming up to allow me to select from the dropdown menu...I have been searching online for hours trying to figure this out and nothing has worked :( any ideas what the problem could be?

Hi, Emma you need to first check that the script is running and that turbolinks is not blocking the recurring event. I use google chrome and the dev terminal to see if its running, there's different ways to check.

Thank you for your response Francisco! I disabled Turbolinks to see if it was blocking the recurring event, but still no luck. I'm wondering if the problem has something to do with the fact that I'm using rails 6 and this video was posted using rails 5 I believe...I am still fairly new to rails, so this is the most complex item I've implemented in my application thus far.

Hello there, I'm trying to use the recurrent_select gem in rails 7 but i'm getting an error
undefined method `field_name' for nil:NilClass

I'm getting this error in the form, when i try creating a new event
<%= form.select_recurring :recurring,nil, allow_blank: true%>
it seems it doesn't recognize "select_recurring", can someone help me pls?

I am getting same issue as jose - rails 7 does not work

Hi, I found a solution in github /GetJobber/recurring_select/pull/152
However the thing is that the js isn´t working for me, I don't know If I'm importing it correctly or how to do it in rails 7

This is not a solution and the code is bad, but since the NPM package is outdated as well as the ruby gem, it at least "works" in Rails 7: https://github.com/robault/event_scheduling

Uses an updated version of the Ruby gem to Rails 7.0.4 and Ruby 3.2.2: https://github.com/robault/recurring_select

Hi Robert,
Thanks for posting your solution. I was able to make it work with Rails 7 too, but my set schedule dialog is ugly.

I wonder if you tried to use the 'until' and 'count' parameters in the recurring rules.
I can't find any documentation on that.
I see a pull request in the recurring_select GitHub repo: https://github.com/gregschmit/recurring_select/pull/117 (Add option to end after a number of occurrances or on a date #117) opened on the same issue.

After creating a recurring event the hash with the rule looks like this:

"recurring"=>"{\"interval\":1,\"until\":null,\"count\":null,\"validations\":{\"day\":[0]},\"rule_type\":\"IceCube::WeeklyRule\",\"week_start\":0}"

where 'until' and 'count' are null.
I would like to set up 'until' and 'count' values too.
Do you have any thoughts on that?
Thank you,
-Rita

Hi Chris.
This is an old episode and an old discussion. But it's still relevant, I watched it and used it in my Rails 7 project. But what I want to add to the Set Schedule dialog are the 'until' and 'count' parameters that are mentioned in the recurring rules. I can't find any documentation on that.

After creating a recurring event the hash with the rule looks like this:

"recurring"=>"{\"interval\":1,\"until\":null,\"count\":null,\"validations\":{\"day\":[0]},\"rule_type\":\"IceCube::WeeklyRule\",\"week_start\":0}"

where 'until' and 'count' are null. I would like to set up 'until' and 'count' values too.

I see a pull request in the recurring_select GitHub repo: https://github.com/gregschmit/recurring_select/pull/117 (Add option to end after a number of occurrances or on a date #117) opened on the same issue.

Do you have examples with all rules' parameters, or could you point me to any documentation?
Thank you,
-Rita

Join the discussion
Create an account Log in

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

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

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