Ordnael
Ordnael

Reputation: 23

Fullcalendar rails: wrongly displaying events sources

I've fullcalendar working in Rails with postgresql. I've a model 'Event' with which i'm trying to feed the calendar using eventSources. The problem is that when the calendar is displayed shows the events with the current date and time, not with the corresponding time and date of the events.

I've been looking at these questions, which I think is related to my problem. But I have not found how to fix it yet.

The code that I have so far:

Event controller

def index
  @events = Event.all
  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @events }
  end
end
private
  def set_event
    @event = Event.find(params[:id])
  end    
  def event_params
    params.require(:event).permit(:title, :start_time, :end_time)
  end

JavaScript

$('#calendar').fullCalendar({

          editable: true,
          eventLimit: true,
          eventSources: [{
              url: '/events'
          }]
});

I must confess I am new to Ruby, so it may be that I'm missing something basic (most likely).

Thanks!

Upvotes: 0

Views: 176

Answers (1)

Navin
Navin

Reputation: 924

try this, Put is method in your event model

  def as_json(options = {})
    {
      :id => self.id,
      :title => self.title,
      :start => self.start_time,
      :end => self.end_time,
     }
  end

and modify fullCalender function's eventSource to this

eventSources: [{
              url: '/events.json'
          }]

Upvotes: 1

Related Questions