Rails nested form for one to many to be shown only once -
i have got 2 models event
, eventlocation
.event
has_many eventlocations
. using nested simple nested form accepting eventlocation
attributes in 'event' form
i have other view conferences. difference between event , conferences events have single event location conference have multiple event locations . there way show event_location form 1 time in event views. right able display event_location form in next way
= f.simple_fields_for :event_locations |event_location| = event_location.input :location %br = event_location.input :start_time %br = event_location.input :end_time %br = event_location.input :address = f.link_to_add "add event location".html_safe, :event_locations
but gives me alternative of adding multiple locations event ,which don't want.
take @ http://api.rubyonrails.org/classes/activerecord/nestedattributes/classmethods.html think link help
model
class fellow member < activerecord::base has_one :avatar accepts_nested_attributes_for :avatar, allow_destroy: true end
http://api.rubyonrails.org/classes/activerecord/nestedattributes/classmethods.html#method-i-accepts_nested_attributes_for
accepts_nested_attributes_for(*attr_names)
ruby-on-rails simple-form nested-forms model-associations
No comments:
Post a Comment