我有以下表格,我也在做CollectionPageImage.new
因为它从另一个模型创建新记录。
= simple_form_for(Spree::CollectionPageImage.new, :url => admin_collection_page_images_url, :html => { :multipart => true, }) do |f|
= render :partial => 'spree/shared/error_messages', :locals => { :target => @collecion_page_images }
= f.input :image, :label => "Collection images: "
= f.association :collection_page
= @collection_page.title
= submit_tag t("create")
创建后,它当前转发到admin_collection_page_images_url或/ collection_page_images
我想在创建每条记录后简单地刷新并保持当前页面,是否有快速完成此操作的方法?
提前谢谢你。
答案 0 :(得分:3)
您的控制器可能有create
个动作,看起来像这样:
def create
@collection_page_image = CollectionPageImage.new(collection_page_image_params)
if @collection_page_image.save
# Here, redirect to the edit page of the just-created record
redirect_to admin_collection_page_image_url(@collection_page_image)
else
flash[:errors] = @collection_page_image.errors
redirect_to action: :new
end
end
如果记录中redirect_to
成功,请注意.save
指令。