Creating recurring events with the ice_cube gem
I am trying to create recurring events using ice_cube and recurring_select gems.
Here is my _form.html.erb code:
<%= 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 %>
In my controller I have (among other things):
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
As you can see, I want to create the same event for every day of the week, but in reality the my: day column remains empty if I submit this form.
Can you provide some feedback? I don't know what could be wrong
source to share
Yours escape_params
seems to be wrong, it should be event_params
like you used in action update
:
private
def event_params
params.require(:event).permit(:day, :start_time, :end_time, :reserved)
end
Update:
After searching the recurring_select
gem, the data it sends to the server looks something like this:
event[:day]: {"interval":1,"until":null,"count":null,"validations":null,"rule_type":"IceCube::DailyRule"}
Thus, it is not a simple single value parameter that can be stored in one field.
Here you have two options: serialize this value and store it in one field, or create separate fields for each parameter in the database.
And since your data in the field day
is a hash, the function permit
just won't work on it. You can see more information on Rails Bug Tracker .
source to share