View monthly calendar in Rails

Introduction

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.

table of contents

  1. Install Simple Calendar
  2. Generate Simple Calendar View
  3. Add an appointment to your calendar
  4. Display calendar

1. Install Simple Calendar

Added" gem ‘simple_calendar’, ‘~> 2.0’ to Gemfile スクリーンショット 2020-10-29 8.57.40.png

Run bundle install in the app's directory

2. Generate a Simple Calendar View

Since the calendar cannot be displayed just by installing Gem, view is generated.

Execute command

$ rails g simple_calendar:views

Folders and files are created.

Apply CSS to the calendar Add ** \ * = require simple_calendar ** to the application.css file スクリーンショット 2020-10-29 9.12.31.png

3. Add an appointment to your calendar

Create a model called event using scaffold

Execute command

$ rails g scaffold Event name start_time:datetime

Perform migration to change the database

$ rails db:migrate

4. Display calendar

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.

~/views/events/index.html.erb


<%= month_calendar events: @events do |date, events| %>
  <%= date %>

  <% events.each do |event| %>
    <div>
      <%= event.name %>
    </div>
  <% end %>
<% end %>

Corrected the appearance and succeeded in displaying the monthly calendar

スクリーンショット 2020-10-29 9.45.46.png

reference

[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!

Recommended Posts

View monthly calendar in Rails
Group_by in Rails
Specify home view in rails app [root]
[Rails] View sharing
[Japanese localization] i18n rails Easy Japanese localization view display only
Implement iteration in View by rendering collection [Rails]
Model association in Rails
Adding columns in Rails
CSRF measures in Rails
^, $ in Rails regular expression
Use images in Rails
Understand migration in rails
Split routes.rb in Rails6
Implement markdown in Rails
Some subtly different repetitive writing styles in Rails View
Calendar implementation and conditional branching in Rails Gem simple calendar
[Rails] How to load JavaScript in a specific view
[Rails] How to display an image in the view
Do not write 〇〇 logic in Rails View (* added later)
Get UserAgent in [Rails] controller
Implement application function in Rails
Declarative transaction in Rails #ginzarb
Implement follow function in Rails
Japaneseize using i18n with Rails
Implement LTI authentication in Rails
Error in rails db: migrate
Gem often used in Rails
Implement import process in Rails
Rails routing controller view relationship
Use multiple checkboxes in Rails6!
Apply CSS to a specific View in Ruby on Rails
Rewrite Routes in Rails Engine
[Rails] How to display information stored in the database in view
View current date in Java
[rails] How to display parent information in child view in nested relationships
(Ruby on Rails6) Creating a database and displaying it in a view
How to write the view when Vue is introduced in Rails?
Rails: Capture regular expressions in emails!
[Rails] Keyword search in multiple tables
[Rails] Session timeout setting in devise
Add a search function in Rails.
[rails] Login screen implementation in devise
[Rails] How to write in Japanese
About the symbol <%%> in Rails erb
[Rails] Use cookies in API mode
Implement simple login function in Rails
Create a new app in Rails
Ruby on Rails Japanese-English support i18n
Implement Material Design View in Kotlin
Mixed Western calendar output in Java
[Solution] Webpacker :: Manifest :: MissingEntryError in Rails
Implement a contact form in Rails
Remove "assets" and "turbolinks" in "Rails6".
CRUD features and MVC in Rails
How to introduce jQuery in Rails 6
First pagination feature added in rails
Data is not registered in Rails.
[Rails 6] Customize Bootstrap in Rails + Bootstrap 5.0.0-alpha environment
[Rails] "Input"-> "Confirmation screen"-> "Save"-> "View"
Implement CSV download function in Rails
Ruby methods often used in Rails