您好我需要在rails中创建重复活动。即每个星期一,我想开会6个月。所以我想把这个事件作为calendar.as中的recurrance事件。我是rails的新手,我已经关注了一些链接。但我没有得到任何关于如何做的代码或想法。我在SO中搜索得很好并且有一个链接。
http://stackoverflow.com/questions/10148960/recurring-events-in-calendar-rails
但是真的不明白他们说了什么。我也审查了一些建议的链接,但这些是用PHP编写的。所以我也无法关注这些链接。请给我一些代码来完成这项任务。有人说我们无法在fullcalendar中实现重复发生的事件。但我不知道它是对还是错。如果它是错的,那么提供一些代码来做到这一点。或者如果你有想法就引导我。提前谢谢。
这是我的控制器:
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
# GET /events
# GET /events.json
def index
@events = Event.all
end
# GET /events/1
# GET /events/1.json
def show
end
# GET /events/new
def new
@event = Event.new
end
# GET /events/1/edit
def edit
end
# POST /events
# POST /events.json
def create
@event = Event.new(event_params)
respond_to do |format|
if @event.save
format.html { redirect_to @event, notice: 'Event was successfully created.' }
format.json { render :show, status: :created, location: @event }
else
format.html { render :new }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
respond_to do |format|
if @event.update(event_params)
format.html { redirect_to @event, notice: 'Event was successfully updated.' }
format.json { render :show, status: :ok, location: @event }
else
format.html { render :edit }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
# DELETE /events/1
# DELETE /events/1.json
def destroy
@event.destroy
respond_to do |format|
format.html { redirect_to events_url, notice: 'Event was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event).permit(:title, :description, :start_time, :end_time)
end
end
这是我的观点:
<p id="notice"><%= notice %></p>
<h1>Listing Events</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Start time</th>
<th>End time</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @events.each do |event| %>
<tr>
<td><%= event.title %></td>
<td><%= event.description %></td>
<td><%= event.start_time %></td>
<td><%= event.end_time %></td>
<td><%= link_to 'Show', event %></td>
<td><%= link_to 'Edit', edit_event_path(event) %></td>
<td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Event', new_event_path %>
<div id="calendar"></div>
<script>
$('#calendar').fullCalendar({
events: '/events.json'});
</script>