[Personal application work memo] Make a calendar with simple_calendar

The calendar was set up.

スクリーンショット 2020-08-23 午後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?

ruby:app/views/calendars/index.html.haml


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

app/controllers/posts_controllers


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

I couldn't display it.

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

How can I display the data in the posts table?

hypothesis

Hypothesis 1: Prepare a start_time column in the posts table. Hypothesis 2: Allow the start_time column in the posts_controller's strong parameter permit. Hypothesis 3: Since the start_time column needs to contain some value, put the default value in the start_time column.

This solved it

posts_controller.rb


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

Now I get today's date and put it in the start_time column of posts_table automatically. By the way, the form for posting does not have a form for entering start_time.

In other words, you don't have to fill out the form When you post, the date of posting is automatically entered in the start_time column. スクリーンショット 2020-08-24 午後11.57.57.png

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

Now that the start_time has a date and time value, I was able to successfully display the event in simple_calendar.

スクリーンショット 2020-08-24 午後11.55.20.png

Recommended Posts

[Personal application work memo] Make a calendar with simple_calendar
[Personal memo] Make a simple deep copy in Java
[Personal application work memo] How to display a bar graph and a line graph in one graph
[Personal application work memo] Move the location of the follow button
Deploy a Docker application with Greengrass
Let's make a book management web application with Spring Boot part1
Make a digging maze with Ruby2D
Personal memo: Metaprogramming with Java reflection
Make a slideshow tool with JavaFX
Let's make a book management web application with Spring Boot part3
Make a Christmas tree with swift
Try to make a cross-platform application with JRuby (jar file generation)
Let's make a book management web application with Spring Boot part2
Make a garbage reminder with line-bot-sdk-java
Build a web application with Javalin
Make a list map with LazyMap
Make a typing game with ruby
[Personal memo] How to interact with a random number generator in Java
[Personal application development work memo] Create an image list page like Instagram
How to make a Java calendar Summary
Let's make a Christmas card with Processing!
Make a family todo list with Sinatra
Create a simple web application with Dropwizard
[Personal] JUnit5 memorandum memo (work in progress)
Make a family todo list with Sinatra
[Personal memo] Writing a file using BufferedWriter
Let's make a smart home with Ruby!
Make a login function with Rails anyway
[docker] [nginx] Make a simple ALB with nginx
Make a site template easily with Rails
[Personal memo] Reading a file using BufferedReader
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
Let's make a calculator application with Java ~ Create a display area in the window
[Personal memo] I learned a little about modifiers
[Memo] Create a CentOS 8 environment easily with Docker
Let's make a search function with Rails (ransack)
Make System.out a Mock with Spock Test Framework