[Ruby] [Personal application work memo] Create a calendar with simple_calendar

1 minute read

The calendar was set up.

Screenshot 2020-08-23 PM 6.35.51.png

I want to add the information of the posts table here.

https://github.com/excid3/simple_calendar Will you proceed with reference to the official page?


  = month_calendar events: @posts do |date, meeting|
    = date
  -posts.each do |post|
    = post.calorie


class CalendarsController <ApplicationController
  def index
    @posts = Post.where(user_id: current_user.id)

This could not be displayed.

https://qiita.com/isaatsu0131/items/ad1d0a6130fe4fd339d0 According to this article, on the table you want to output to a calendar t.datetime :start_time It seems that you need to set it.

How can I display the data in the posts table?


Hypothesis 1: Prepare the start_time column in the posts table. Hypothesis 2: Allow the start_time column in permit of posts_controller strong parameter. Hypothesis 3: It is necessary to have some value in the start_time column, so put a default value in the start_time column.



@post = Post.new(post_params)
 #Get today's date (for simple_calendar)
@post[:start_time] = Date.today.strftime('%Y-%m-%d')

With this, today’s date is fetched and automatically put in the start_time column of posts_table. By the way, the form for entering start_time is not prepared in the form for posting.

In other words, without filling in the form If you post, the date you posted will be automatically entered in the start_time column. Screenshot 2020-08-24 11.57.57.png PM

If there is no value in this red frame part Not displayed as an event.

Now that the start_time contains the date and time value, I was able to display the event in simple_calendar safely.

Screenshot 2020-08-24 11.55.20.png PM-345dfed576a4.png)