Hi,
I''m trying to ''add appointments with schedules''
so I have
class Appointment < ActiveRecord::Base
has_many :schedules
accepts_nested_attributes_for :schedules, :allow_destroy => true
end
and
class Schedule < ActiveRecord::Base
has_paper_trail
belongs_to :appointment
end
and my AppointmentsController has this create action
def create
resource = new_resource
if resource.update_attributes(params[:appointment])
flash[:notice]= "Perfect"
else
flash[:warning]= "Errors"
end
end
and my appointments/new.html.erb looks like
<% semantic_form_for resource,
:html => { :class => "oxform" },
:url => resources_url do |form| %>
<%= render :partial => "/appointments/form", :locals => {
:form =>
form } %>
<% form.buttons do %>
<input class="cta button" type="submit"
value="Create"/>
<% end %>
<% end %>
Finally my _form.html.erb''s are like
appointments/_form.html.erb:
<% form.inputs :appointment_form do %>
<%= form.input :title %>
<% form.semantic_fields_for :fields do |fld| %>
<%= fld.input :location %>
<%= fld.input :category %>
<% end %>
<li>
<ul id="schedules">
<% form.fields_for :schedules do |builder| %>
<%= render ''schedule'', :fld => builder %>
<% end %>
<li>
<%= link_to_add_schedule("Add Schedule", form, :schedules)
%>
</li>
</ul>
</li>
appointments/_schedule.html.erb:
<li class="schedule">
<ol>
<%= fld.input :first_date, :as => :string %>
<%= fld.input :last_date, :as => :string %>
<%= fld.input :all_day_event, :as => :oxboolean %>
<%= fld.input :repeating, :as => :oxboolean %>
<%= fld.hidden_field :id %>
<%= fld.hidden_field :_destroy %>
<%= link_to_function "Drop Schedule",
"removeSchedule(this)" %>
</ol>
</li>
You in ''the know'' already have spotted that I''m
trying to use Formtastic
and Ian Whites fabulous resources_controller -
Like I said in the subject: when I POST the appointments/new - I get two
schedules added every time - even though the params look like this:
Processing AppointmentsController#create (for 127.0.0.1 at 2010-04-28
13:20:00) [POST]
Parameters: {"appointment"=>{"title"=>"og endnu
et",
"schedules_attributes"=>{"0"=>{"first_date"=>"",
"last_date"=>""}}},
"authenticity_token"=>"RO3cWfhF+2wfH6hXzG0HwDByHLcxl9yAOMBLPk0PRaI=",
"calendar_id"=>"16"}
Every thing is fine - I just get that extra schedules added to my
schedules table - as a way for Rails 2.3.5 to say "thank you" :)
Have I involuntarily stepped on a bug - most likely I''ve just mixed
gems
and plugins that do not like each other/Rails 2.3.5, or left the obvious
''some statement'' untouched, grinning back at me from somewhere
deep
within vendor/..
Please if someone has the upperhand on this one - throw me rope <:)
Cheers,
Walther
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.