我正在做我的Ruby作业从学校。我需要使一天(星期日,星期一等)出现在日历应用程序。下面是原始代码中的问题,我收到;
class CalendarsController < ApplicationController
def index
getWeek
@plan = Plan.new
end
def create
Plan.create(plan_params)
redirect_to action: :index
end
private
def plan_params
params.require(:calendars).permit(:date, :plan)
end
def getWeek
wdays = ['(Sun)','(Mon)','(Tue)','(Wed)','(Thu)','(Fri)','(Sat)']
@todays_date = Date.today
@week_days = []
plans = Plan.where(date: @todays_date..@todays_date + 6)
7.times do |x|
today_plans = []
plans.each do |plan|
today_plans.push(plan.plan) if plan.date == @todays_date + x
end
days = { :month => (@todays_date + x).month, :date => (@todays_date+x).day, :plans => today_plans}
@week_days.push(days)
end
end
end
字符串
我试着写了如下代码:
@todays_date = Date.today.wday
型
我希望看到日期(Sun,Mon等)出现在应用程序上
1条答案
按热度按时间x759pob21#
今天是星期三。当你想把一个日期转换成星期几的字符串表示时,你可以像这样使用
Date#strftime
:字符串