1

I have this bit of code refreshing the event when I update it.

event/update.js.erb

$('#calendar').fullCalendar('removeEvents', [<%= @event.id %>]);
$('#calendar').fullCalendar(
  'renderEvent',
  $.parseJSON("<%=j render(@event, format: :json).html_safe %>"),
  true
);

Lot of my events are related and I would like to be able to call this manually on every event every time as one of them is updated.

I'm trying to do something like this but I've no idea how to make the javascript call and it doesn't feel right either.

  def update        
    @event.update(event_params)

    Event.all.each do |event|
      # call event's javascript
    end

  end

Any suggestions on this ?

1 Answer 1

2

If you want to do it every time, just do it in the view.

# controller
def update        
  @event.update(event_params)
  @events = Event.all
end

# update.js.erb
<% @events.each do |event| %>
  $('#calendar').fullCalendar('removeEvents', [<%= event.id %>]);
  $('#calendar').fullCalendar(
    'renderEvent',
    $.parseJSON("<%=j render(event, format: :json).html_safe %>"),
    true
  );
<% end %>
Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly what I was looking for. Didn't think it could be that easy. Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.