Two ajax requests are being used on a single page, one showcasing a date and the other displaying a calendar.
The first request updates the date upon clicking a date on the calendar.
The second request allows for switching between months on the calendar.
The issue is that both functions are in index.js.erb, causing both to execute simultaneously and resetting the date in the first request whenever the month is changed.
Is there a way to have only one function from index.js.erb execute at a time?
Index.js.erb
$("#calendar").html("<%= escape_javascript(render('layouts/calendar')) %>");
$("#today").html("<%= escape_javascript(render('layouts/today')) %>");
_today.html.erb
<div class="span3 offset2 dateToday">
<% end %>
<span id="currentdate">
<%= @eventDate.strftime("%B") %><br>
<span id="dayDate"><%= h @eventDate.day %></span>
</span>
</div>
_calendar.html.erb
<h2 id="month">
<span class="pull-left"><%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m-01") %></span>
<%= h @date.strftime("%B %Y") %>
<span class="pull-right"><%= link_to ">", :month => (@date.end_of_month+1).strftime("%Y-%m-01") %></span>
</h2>
<%= calendar_for(@events, :year => @date.year, :month => @date.month) do |t| %>
<%= t.head('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') %>
<%= t.day(:day_method => :eventdate) do |date, events| %>
<div class="day">
<%= link_to(date.day, {:day => date }, :remote => true, :class => "btn dayBtn") %>
</div>
<% end %>
EDIT: routes.rb
resources :calendar
root :to => "calendar#index"
match '/faq', to: 'calendar#faq'
match ':controller/:action'
EDIT - link to ajax action
<%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m-01"), :action => "update_calendar", :remote => true %>
Thank you!