Reputation: 4116
I have the following form, also I'm doing CollectionPageImage.new
because its creating new record from another model.
= 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")
After it is created it is currently forwarding to admin_collection_page_images_url or /collection_page_images
I would like it to simply refresh and stay on the current page after each record is created, is there a quick way accomplish this?
Thank you in advance.
Upvotes: 1
Views: 1128
Reputation: 54882
You probably have a create
action of your controller that looks kind of like this:
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
Notice the redirect_to
instruction if the .save
is successfull on the record.
Upvotes: 3