3

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 each day in a week, but actually my :day column remains empty if I submit this form.

Can you give some feedback? I don't know what can be wrong

Paulina
  • 61
  • 4

1 Answers1

1

Your escape_params seems to be wrong, it should be event_params as you have used in the update action:

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

Update:

After looking into recurring_select gem, the data that it is sending to the server is something like this:

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

So it is not a simple single value parameter that you can store in a single field.

You have two choices here, either serialize this value and store it in a single field or create separate fields for each parameter in the database.

And since your data in day field is a hash, permit function simply won't work on it. You can see more information on Rails issue tracker.

Loqman
  • 1,487
  • 1
  • 12
  • 24
  • Sorry, it was a type error during copying the code. I corrected it now. Unfortunately that's not the problem – Paulina Aug 02 '15 at 19:00