gem ice_cube for reccurence events
Asked Answered
O

1

5

I have simple Event model (title, date, user) And I created Events Calendar by months (gem 'watu_table_builder'). I need the feature to create repeating events. I figured out that I may use gem ice_cube for it. But it is not clear for me.

I added to model:

class Event < ActiveRecord::Base
  #require 'ice_cube'
  include IceCube

  belongs_to :user

  validates :title, :presence => true,
                    :length => { :minimum => 5 }
  validates :shedule, :presence => true

  def self.events_and_repeats(date)
    @events = Event.where(shedule:date.beginning_of_month..date.end_of_month)

# Here I need to figure out what is events repeats at this month (from date param)
# how I may combine it with Events array

    @events_repeats = @events # + repeats

    return @events_repeats

  end

1) How I may combine repeat rules with Events array?

2) As I understand, I may save to db information about repeats in yaml yaml = schedule.to_yaml

But it is not clear for me how it is good way to create drop-down for repeats (none, each day, each month, each year) and link it with shedule rules. Where and how I should realize it (convert user choise to right shedule)

Onlybegotten answered 3/4, 2013 at 14:59 Comment(3)
What is "gem calendar_table" and what does it do? I can't find it.Anatol
Sorry, it is 'watu_table_builder'.Onlybegotten
It is just created calendar at page. My code in index.html.erb is <%= calendar_for(@events, :year => @date.year, :month => @date.month) do |calendar| %> .................... <% end %>Onlybegotten
A
1

You won't be able to query the database for the Event's serialized (yaml) schedule to filter occurrences by month, if that's what you're trying to do. If you need to do that, then you'll have to store the schedule.occurrences as rows in a separate table join: that's what I do in our app.

I might have more details to add to this answer later, meanwhile have a look at my schedule_attributes gem if it helps you build the selectors for building schedules from user input (I still need to update docs and release it...)

Anatol answered 5/4, 2013 at 19:40 Comment(2)
How could I store a recurrence rule in database? I might save a schedule in db repeats = schedule.to_hash or repeats = schedule.to_yaml then use it from db schedule = repeats.from_hash But I need to know what is a rule. For example, if it is repeated weekly, how could I store a rule in db or how could I know rule from schedule? Is it some methods like .to_hash and .from_hash for rules?Onlybegotten
Thanks for putting together this library. Looking forward to the docs update and official release. I will be attempting to implement something similar to to @gabiEla

© 2022 - 2024 — McMap. All rights reserved.