My RoR website implements a calendar using the fullcalendar
gem. Each user has a calendar that shows the events which he or she is attending. The following scenario sets the stage for my question:
- User Alice clicks an event on her calendar, which leads to the event's
show
page. - Alice clicks the 'unattend event' button on the event's
show page
- Alice clicks the back button.
- The event that she just unattended is still listed on her calendar.
How can I make the browser refresh Alice's event information, so that only events that she is currently attending are displayed, when the back button is pressed?
I've scoured Stack Overflow and not found a working solution. Cache clearing as seen here How to prevent browser page caching in Rails did not work. I'm not even sure this is a caching problem. Perhaps there is some javascript that will force information to be reloaded? Any solutions are much appreciated. Thanks!
In response to @ElliottRoche:
The attend button is clicked in the view, triggering the attend action:
<%= button_to button_text, attend_event_path(@event), :remote => true, :id => "attend" %>
The attend action adds/removes the attendee from the list of attendees as follows:
def attend
@event = Event.find(params[:id])
@attendee = User.find(session[:user_id])
if @event.users.exclude?(@attendee)
@event.users << @attendee
@event.save
else
@event.users.delete(@attendee)
end
@attendees = @event.users
respond_to do |format|
format.js
format.html { }
format.json { }
end
end
With attend.js.erb, the attendees list is updated using UJS:
$('#attendees-list').html("<%= j render(:partial => 'attendees_list', :locals => { :attendees => @attendees }) %>");
From here, when the back-button is pressed, the fact that the user has attended/unattended the event is not reflected.