是否有可能在每天的fullcalendar中设置事件限制?
我没有问题设置显示事件的限制(已经这样做),但我不知道如何为现有事件做到这一点。fullcalendar - 事件的每日限制
0
A
回答
0
好的,我设法处理了太多事件的创建。
首先,你必须计算事件在一个特定的一天发生,并检查新的是否是要通过你的极限,所以在你的模型:
def daily_events_limit(date)
date.each do |d|
if Event.where('start_date <= ? AND end_date >= ?', d, d).count > 4
break false
end
true
end
然后,在你的控制器:
def create
@event = Event.new(event_params)
if ([email protected]_events_limit(@[email protected]_date))
redirect_to @event, notice: 'You cannot get free day in selected period of time.'
else
...
end
end
在这种情况下,您无法创建新事件,该事件将以5个事件开始,结束或传递日期。
我不知道这是否是一种优雅的方式做处理这个问题,但它的工作原理:)
0
通常逻辑防止类对象的创建/删除/更新的模式应该发生。这可以让你确保你的规则总是被检查,而不仅仅是那个控制器中的那个实例。您可以使用验证来做到这一点:
在型号:
class Event < ActiveRecord::Base
validate :validate_event_limit
private
def validate_event_limit
if Event.where(start_date: self.start_date.beginning_of_day..self.start_date.end_of_day).count > 4
errors[:base] << "You cannot get free day in selected period of time."
end
end
end
在控制器:
def create
@event = Event.new(event_params)
if @event.save
...
else
redirect_to @event, notice: @event.errors.full_messages
end
end
这将会从每天创建停止第五事件。因为您使用了验证,所以您可以使用相同的逻辑来检查可能会将活动从一天移动到另一天的更新:
def update
if @event.update(event_params)
...
else
redirect_to @event, notice: @event.errors.full_messages
end
end
相关问题
- 1. 每日限制
- 2. FullCalendar - 限制
- 3. FullCalendar计数每日客户端事件的总数
- 4. Javascript Fullcalendar - 复制事件
- 5. 获取功能的日历事件fullCalendar
- 6. 事件日期的FullCalendar提醒
- 7. 在UI日历每个事件自定义按钮fullcalendar
- 8. fullcalendar,我想每天计算事件
- 9. Fullcalendar JSON事件的定制开始/结束日期
- 10. FullCalendar限制事件数量,并有一个更多链接
- 11. Fullcalendar经常性事件限制(使用dow)
- 12. FullCalendar - 谷歌日历事件颜色
- 13. FullCalendar中的事件
- 14. 在日冕中限制触摸事件
- 15. 事件源FullCalendar
- 16. jQuery fullcalendar - 事件
- 17. Fullcalendar叠加事件
- 18. Fullcalendar事件渲染
- 19. Fullcalendar添加事件
- 20. Fullcalendar重取事件
- 21. FullCalendar事件删除
- 22. Fullcalendar添加事件
- 23. Fullcalendar的外部事件
- 24. FullCalendar的事件函数
- 25. Fullcalendar中的更新事件
- 26. Windows事件日志权限
- 27. 限制事件的发生
- 28. Fullcalendar - 将月份限制在月视图中的单一全天事件
- 29. 检索Salesforce每日Api请求限制
- 30. 限制每日提交到数据库