如何在CSS的Helper中使用==模型方法类?

时间:2015-09-17 19:24:30

标签: html css ruby-on-rails ruby helper

calendar_helper

def day_classes(day)
  classes = []
  classes.empty? ? nil : classes.join(" ")
  classes << "future" if day > Date.today # This make future days a white background, by default days are blue background
  # The Below Line Gives an Error (I want missed_dates date_missed to be red background): 
  classes << "missed" if day == current_user.missed_dates.group_by {|i| i.date_missed.to_date}
end

Pages#home中的NameError

undefined local variable or method 'current_user'

CSS

.future { background-color: #FFF; }
.missed { background-color: red; }

我使用railscasts tutorial建立日历。

1 个答案:

答案 0 :(得分:1)

将此行添加到public static void main(String[] args) { Scanner inp = new Scanner(System.in); int i=0; String in = inp.nextLine(); while(i==0){ if(in.equals("x")){ System.out.println("> y"); }else{ System.out.println("input != x"); } in = inp.nextLine(); } 班级:

Calendar

由于delegate :current_user, to: :view 会自动包含在视图中,因此应该能够将SessionsHelper变量传递给您的view类。

  

感谢您删除了错误,但由于某种原因,我标记为date_missed的日期没有变成红色

我猜Calendar是错过日期的数组,因此,为了检查您的日期是否在该数组中,请使用current_user.missed_dates.group_by {|i| i.date_missed.to_date}

include?