用户如何选择一周中的几天?

如何为一周中的每一天创建一个复选框,使其如下所示:

[]太阳[]星期一[]星期二[]星期三[]星期四[]星期五[]星期六

然后,用户将在_form中检查他承诺进行30天习惯挑战的日期。

EX:

[]太阳[✓]星期一[✓]星期二[✓]星期三[✓]星期四[✓]星期五[星期六]星期六

我不认为字符串或类似下面的东西会起作用:

EX 1 
  • EX 2

    因为我希望每一天能够真实地代表日历上的每一天,这样我才能最终弄清楚我如何根据他的开始日期以及他多少天来计算他在30天的习惯挑战中剩下的天数。承诺/错过。

    但回到这个具体问题:

    如何为一周中的每一天创建复选框? 此function适用于:days

       
        

    [:month, :day, :year], class: 'date-select' %>

     class HabitsController < ApplicationController before_action :set_habit, only: [:show, :edit, :update, :destroy] before_action :correct_user, only: [:edit, :update, :destroy] before_action :authenticate_user!, except: [:index, :show] def index @habits = Habit.all end def show end def new @habit = current_user.habits.build end def edit end def create @habit = current_user.habits.build(habit_params) if @habit.save redirect_to @habit, notice: 'Habit was successfully created.' else render action: 'new' end end def update if @habit.update(habit_params) redirect_to @habit, notice: 'Habit was successfully updated.' else render action: 'edit' end end def destroy @habit.destroy redirect_to habits_url end private def set_habit @habit = Habit.find(params[:id]) end def correct_user @habit = current_user.habits.find_by(id: params[:id]) redirect_to habits_path, notice: "Not authorized to edit this habit" if @habit.nil? end def habit_params params.require(:habit).permit(:missed, :left, :level, :days, :date_started, :trigger, :action, :target, :positive, :negative) end end 

    在此先感谢您的帮助!

    Github: https //github.com/RallyWithGalli/ruletoday

    我认为这是最好的方法:

     <%= f.label "Committed to:" %>  <% Date::DAYNAMES.each do |day| %> <%= f.check_box :days, {}, day %> <%= day %> <% end %>