Since we are developing an application using Simple Calendar, which is a Rails gem, we will explain the introduction and basic usage of Simple Calendar for later study.
The content is a Japanese translation of simple_calendar's official GitHub.
It is a gem that makes it easy to implement the calendar display function.
Write the following in the Gemfile
and enter bundle install
in the terminal.
Gemfile
gem "simple_calendar", "~> 2.0"
Terminal
bundle install
Load the default stylesheet into the application.css
file.
app/assets/stylesheets/application.css
*= require simple_calendar
Alternatively, write the following in the application.scss
file.
app/assets/stylesheets/application.scss
@import "simple_calendar";
Describes how to use the Simple Calendar method to generate a calendar in a view file.
You can generate a monthly calendar using the month_calendar
method.
month.html.erb
<%= month_calendar do |date| %>
<%= date %>
<% end %>
You can generate a weekly calendar using the week_calendar
method.
You can set how many weeks to display with the optional number_of_weeks
. If number_of_weeks
is not described, it will be displayed for one week by default.
week.html.erb
<%= week_calendar(number_of_weeks: 2) do |date| %>
<%= date %>
<% end %>
You can customize the number of days displayed in the calendar by using the calendar
method.
You can set how many days are displayed with the option number_of_days
. If you do not write number_of_days
, it will be displayed for 4 days by default.
custom.html.erb
<%= calendar(number_of_days: 4) do |date| %>
<%= date %>
<% end %>
This is the end of the process from the introduction of Simple Calendar to the basic usage.
If you want to edit the appearance of each calendar, enter the following command and copy the view file to your own app.
Terminal
rails g simple_calendar:views
#Simple as follows_A calendar folder and each view file will be generated in your app
create app/views/simple_calendar
create app/views/simple_calendar/_calendar.html.erb
create app/views/simple_calendar/_month_calendar.html.erb
create app/views/simple_calendar/_week_calendar.html.erb
-Simple_calendar's official GitHub -Qiita [Rails] Calendar display using Simple Calendar -Qiita [rails] I made a blog function with a calendar using simple_calendar.
Recommended Posts