You can set `sorted = Hash.new()` in `sorted_events` so that you don't have to be defensive in the view.
Hey Chris! I've been using this gem to get a better feel for it and came across a question. I posted on stackoverflow and was wondering if you could give it a look?
Thanks in advance! I built an app combining 2 of your episodes (multitenancy from scratch & simple_calendar) to also practice json. To summarize the stackoverflow post: I want to use json to update the calendar along with the index when I create a new event. Here's a link to the app (click)
The easiest way is actually to use a JS response that sends back the calendar partial and you can just simply replace that part of the page. I made this a while back to show how that's done: https://github.com/excid3/s...
Let me know if that makes sense and accomplish what you're trying to do!
Instead of rendering 3 separate pages for a new event form, showing events, and finally the index page, I wanted to do all of that plus display the monthly calendar all in one page. That way when I created a new event it would update everything on one click.
You can definitely do all that, but yeah...it might be a lot for your first venture into JS land! :) You can absolutely add the form in the same page and use the example I linked to for updating the calendar after you create a new event though. Shouldn't be too hard.
Hey Chris! Is there a way I can display color coded events based on an event_type? Say in this example I could have "work_meetings" or "personal_meetings" and one would be blue and the other one yellow. Is there a way to achieve this?
Absolutely! You can just pass in an array with all the meetings and then inside the block you can print them out differently using a helper or something. Rough outline here, first section goes in the controller.
# Pass @meetings into the calendar
@meetings = work_meetings + personal_meetings
<% month_calendar meetings: @meetings do |day, meetings| %>
<% meetings.each do |meeting| %>
<% if meeting.meeting_type == "work_meeting" %>
Code for work meeting
<% else %>
Code for personal meeting
<% end %>
<% end %>
<% end %>
Hey Chris. I Just wanted to thank you for the quick response.
I'm actually very happy with the simple_calendar gem. At first I was a bit confused due to the simplicity ("wait is this just a table with dates?") but as I saw how easy it's been to extend and customize for my use case I'm honestly loving it.
So thanks again for putting out great things to the rails community!
Thanks for the kind words Felipe! I really appreciate it. :) Really glad you like the gem and the architecture of it! I think the videos turned out to be really fantastic documentation that I never planned. :)
Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.