I'm a noob at rails, and think this may be a very basic problem. I've tried changing the validations, but hasn't worked. My logs and code follow.
It's a nested_form_for :order, which has_many :order_dates. I think the problem is on the nested form.
- Gemfile includes "gem 'nested_form'"
- I have the javascripts/nested_forms.js file.
- Application includes "//= require jquery_nested_form"
- Layout includes "<%= javascript_include_tag :defaults, "nested_form" %>"
Logs:
Started POST "/orders" for 99.234.104.113 at 2016-05-07 23:47:07 +0000
Processing by OrdersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"<this_token>", "order"=>{"user_id"=>"2", "school_id"=>"1", "district_id"=>"1", "facility_school_id"=>"2", "date_orders_attributes"=>{"0"=>{"_destroy"=>"false", "order_date"=>"2017-01-01", "time_start"=>"15:00", "time_end"=>"16:00"}}, "purpose"=>"Meeting or workshop", "attendees"=>"Example School", "attendees_number"=>"12", "description"=>"hey", "full_name"=>"Lil Kim", "user_group"=>"this", "email"=>"lil@kim.com", "phone_number"=>"", "occupation"=>""}, "commit"=>"Request to book"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
School Load (0.1ms) SELECT "schools".* FROM "schools" WHERE "schools"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
order.rb
class Order < ActiveRecord::Base
belongs_to :user
belongs_to :school
belongs_to :facility_school
belongs_to :district
has_many :date_orders, :dependent => :destroy
validates :user, presence: true
validates :school, presence: true
validates :facility_school, presence: true
accepts_nested_attributes_for :date_orders, :allow_destroy => true
end
order/new.html.erb
<%= nested_form_for @order do |f| %>
<%= f.hidden_field :user_id, :value => current_user.id %>
# SOME MORE HIDDEN FIELDS #
<%= f.fields_for :date_orders do |builder| %>
<%= builder.date_field :order_date %>
# SOME MORE NESTED FIELDS #
<% end %>
<%= f.link_to_add "add date", :date_orders %>
<%= f.select :attendees, options_for_select(["one", "two", "three"]), class: 'form-control' %>
# SOME MORE FIELDS #
<%= f.submit "Order", class: "btn btn-blue" %>
Aucun commentaire:
Enregistrer un commentaire