用户如何选择一周中的几天?
如何为一周中的每一天创建一个复选框,使其如下所示:
[]太阳[]星期一[]星期二[]星期三[]星期四[]星期五[]星期六
然后,用户将在_form中检查他承诺进行30天习惯挑战的日期。
EX:
[]太阳[✓]星期一[✓]星期二[✓]星期三[✓]星期四[✓]星期五[星期六]星期六
我不认为字符串或类似下面的东西会起作用:
EX 1 EX 2
因为我希望每一天能够真实地代表日历上的每一天,这样我才能最终弄清楚我如何根据他的开始日期以及他多少天来计算他在30天的习惯挑战中剩下的天数。承诺/错过。
但回到这个具体问题:
如何为一周中的每一天创建复选框? 此function适用于:days
。
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 %>
- Rails 4:使用merit gem创建点规则
- 如何以轨道forms处理多个模型
- Rails – 使用Tempfile在Heroku上写?
- Rails有很多条件
- 在我的Rails应用中包含Google Analytics嵌入API第三方信息中心示例javascript
- 为什么在around_filter或after_filter中的redirect_to不起作用?
- 使用Rails 3和Haml 3,如何配置Haml?
- 如何使用gem’inlease’登录用户的完整个人资料信息,:git =>“git://github.com/pengwynn/linkedin.git”?
- JS文件双重包含在rails app中