簡體   English   中英

使用ice_cube gem創建重復活動

[英]creating recurring events with ice_cube gem

我正在嘗試使用ice_cube和recurring_select寶石創建重復活動。

這是我的_form.html.erb代碼:

<%= simple_form_for(@event) do |f| %>
  <div class="form-inputs">
    <%= f.select_recurring :day, [IceCube::Rule.daily]  %>
    <%= f.input :start_time %>
    <%= f.input :end_time %>
  </div>
  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

在我的控制器中,我(除其他外):

def new
   @event = Event.new
end

def create
  @event = Event.new(event_params)
  respond_to do |format|
    if @event.save
      format.html { redirect_to @event, notice: 'Event was successfully created.' }
      format.json { render :show, status: :created, location: @event }
    else
      format.html { render :new }
      format.json { render json: @event.errors, status: :unprocessable_entity }
    end
  end
end

def event_params
  params.require(:event).permit(:day, :start_time, :end_time, :reserved)
end

如您所見,我想在一周內為每天創建相同的事件,但如果我提交此表單,實際上我的:day列仍為空。

你能提供一些反饋意見嗎? 我不知道什么是錯的

您的escape_params似乎是錯誤的,它應該是您在update操作中使用的event_params

private
  def event_params
    params.require(:event).permit(:day, :start_time, :end_time, :reserved)
  end

更新:

在查看recurring_select gem之后,它發送到服務器的數據是這樣的:

event[:day]: {"interval":1,"until":null,"count":null,"validations":null,"rule_type":"IceCube::DailyRule"}

因此,您可以將其存儲在單個字段中,這不是一個簡單的單值參數。

這里有兩個選擇,序列化此值並將其存儲在單個字段中,或為數據庫中的每個參數創建單獨的字段。

由於您在day字段中的數據是一個哈希,因此permit函數根本無法使用。 您可以在Rails問題跟蹤器上查看更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM