簡體   English   中英

Rails創建新記錄而不重定向而是刷新並保留在當前頁面上

[英]Rails create new record without redirect instead refresh and stay on current page

我有以下形式,我也在做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

我想在創建每條記錄后簡單地刷新並保持當前頁面,是否有快速完成此操作的方法?

先感謝您。

您可能有一個控制器的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

如果.save在記錄上成功,請注意redirect_to指令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM