Date not saving within parameters of model

Viewed 17

within my view form, I currently have this code:

<div class="panel panel-default">
  <div class= "panel-body">
    <%= form_for @meal_plan, url: new_meal_plan_path, method: "GET", html: { class: "form-inline" } do |form| %>
      <div class="form_group">
        <%= form.label :start_date %>
        <%= form.text_field :start_date, type: "date", class: "form-control" %>
      </div>

      <div class="form_group">
        <%= form.label :end_date %>
        <%= form.text_field :end_date, type: "date", class: "form-control" %>
      </div>

      <div class="form-group action">
        <%= form.submit "Generate Plan", class: "btn btn-default"%>
      </div>
    <% end %>
  </div>
</div>

That takes a start date and an end date input for a meal plan. In the new method within the meal_plan_controller, I have:

def new
  puts params[:start_date]
  puts params[:end_date]
  @meal_plan = current_user.meal_plans.build(
    start_date: params[:start_date] || Date.today,
    end_date: params[:end_date] || 6.days.from_now.to_date,
  )
  @meal_plan.build_meals
end

In the puts statements that I wrote to debug, :start_date and :end_date contains only the default dates, so my guess is that the dates are not saving when the user hits submit, but I can't figure out why.

0 Answers
Related