我试图使用一个表单(事件表单)保存两个对象(图像和事件), 但是当我提交按钮时,只有创建的事件对象,图像对象不保存到图像表,
模型/ event.rb
has_one :images, :class_name => '::Refinery::Image'
accepts_nested_attributes_for :images, :allow_destroy => true
模型/ image.rb
belongs_to :events, class_name: 'Refinery::Events::Event'
events_controller.rb
def new
@event = Event.new
@event.build_images
end
def create
@event = Event.new(event_params)
end
def event_params
params.require(:event).permit(:nama, :deskripsi, images_attributes:[:id, :image_name, :image_size, :image_width, :image_height, :created_at, :updated_at, :image_mime_type, :image_uid, :image_title, :image_alt, :event_id] )
end
事件/ _form.html.erb
<%= form_for [refinery, :events, @event], :html => { :multipart => true } do |f| %>
<%= render '/refinery/admin/error_messages',
:object => @event,
:include_object_name => true %>
<div class='field nama_field string_field'>
<%= f.label :nama %>
<%= f.text_field :nama %>
</div>
<div class='field deskripsi_field text_field'>
<%= f.label :deskripsi %>
<%= f.text_area :deskripsi, :rows => 8 %>
</div>
<%= f.fields_for :images do |ff| %>
<div>
<%= ff.label :images %>
<%= ff.file_field :images %>
</div>
<% end %>
<div class='actions'>
<%= f.submit t('.send') %>
</div>
<% end %>
任何人都可以帮助我为什么图像没有保存到图像表中?