The calendar was set up.
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.
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.
↓
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.
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.
Recommended Posts