Last active
August 13, 2017 20:44
-
-
Save davidwessman/7597e3eea4e71238d7f71a74928e64bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calendar = { | |
initialize() { | |
const calendars = document.getElementsByClass('fullcalendar'); | |
Array.from(calendars).forEach(function(cal) { | |
const place = cal.dataset.place; | |
cal.html(''); // Remove any previous calendar | |
cal.fullCalendar({ | |
eventSources: [{ url: '/events/feed.json?place=' + place }], | |
other_options:... | |
}); | |
}); | |
}, | |
}; | |
document.addEventListener('turbolinks:load', function(cal) { | |
calendar.initialize(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventsController | |
def feed | |
@events = set_events | |
end | |
def index | |
@place = params.fetch(:place, nil) | |
end | |
def set_events | |
if params[:place].present? | |
Event.place(params[:place]) | |
else | |
Event.all | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json.events(@events) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% form_with(url: events_path) do |form| %> | |
<%= form.text_field('place') %> | |
<%= form.submit %> | |
<% end %> | |
<% if @place.present? %> | |
<div class='fullcalendar' data-place="<%= @place %>"></div> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@knzudgt I did not see this reply before.
If you add the
feed.json.jbuilder
you will not need theindex.json.jbuilder
.I think the
event_url
looks great.