Record until the monthly calendar is displayed on the original application. There is a method to use SimpleCalendar and FullCalendar for the calendar function. This time, we will introduce Simple Calendar.
Added" gem ‘simple_calendar’, ‘~> 2.0’ to Gemfile
Run bundle install in the app's directory
Since the calendar cannot be displayed just by installing Gem, view is generated.
$ rails g simple_calendar:views
Folders and files are created.
Apply CSS to the calendar
Add ** \ * = require simple_calendar ** to the application.css file
Create a model called event using scaffold
$ rails g scaffold Event name start_time:datetime
Perform migration to change the database
$ rails db:migrate
Since I used scaffold, the code is written in the file of index.html.erb, but I will edit it. Rewrite the index.html.erb file in the events folder.
<%= month_calendar events: @events do |date, events| %> <%= date %> <% events.each do |event| %> <div> <%= event.name %> </div> <% end %> <% end %>
[Official document] simple_calendar [Rails] I made a blog function with a calendar using simple_calendar. [Rails] Let's display the calendar with Simple Calendar!