Skip to content

Instantly share code, notes, and snippets.

@Frank004
Last active Jun 29, 2017
Embed
What would you like to do?
#this events are on the fly and not store in the database.
# you can make some other code to create the record.
event.converted_schedule.occurrences_between(event.start_date,event.end_date).each do |date|
event_duration_date = (date.to_date + event.duration.days).to_date
@events << {
title: event.name,
event_id: event.id,
start: date,
end: event_duration_date,
description: event.description,
allDay: true,
color: event.color,
}
end
@events.to_json
# you can use something like this to build your event in db's
# this example take 1 month only
event.converted_schedule.occurrences_between(Time.now,Time.now.end_of_month).each do |e|
...
end
class Event < ActiveRecord::Base
has_many :recurrents, dependent: :destroy
#--------------recuring model ------------------------------------------------
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
serialize :schedule, Hash
def schedule=(new_schedule)
if RecurringSelect.is_valid_rule?(new_schedule)
write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_hash)
end
end
def converted_schedule
if !self.read_attribute(:schedule).empty?
the_schedule = IceCube::Schedule.new( self.start_date )
the_rule = RecurringSelect.dirty_hash_to_rule( self.read_attribute(:schedule) )
if RecurringSelect.is_valid_rule?(the_rule)
the_schedule.add_recurrence_rule( the_rule)
end
the_schedule
end
end
end
class Recurrent < ActiveRecord::Base
belongs_to :event
end
<script type="text/javascript">
$(document).ready(function(){
$('#calendar').fullCalendar({
locale: 'es',
events: '/event/'+event_id+'/schedule',
eventLimit: 4,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventRender: function(event, element) {
$(element).tooltip({title: "Descripción: " + event.description});
},
loading: function(bool) {
if (bool)
$('#calendar-loading').show();
else
$('#calendar-loading').hide();
},
firstDay: 1,
//this section is triggered when the event cell it's clicked
selectable: true,
selectHelper: true
});
});
</script>
<ul>
<% @event.converted_schedule.next_occurrences(5, DateTime.now).each do |e| %>
<li>
<%= e.strftime('%d/%b/%Y') if e <= @event.end_date %>
</li>
<% end %>
</ul>
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 20, 2016

hey francisco. where do i put the build_event that you provided? it should be in the event model right? and if so, what does recurring model do? thanks man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment