From 5740fb92e37a833187a716f3b16ea13d53b0f0f0 Mon Sep 17 00:00:00 2001 From: Cedric Tang Date: Thu, 7 Jun 2018 17:32:46 -0700 Subject: [PATCH] Fix error when clicking on 'save & continue' then changing locale --- .../refinery/blog/admin/posts_controller.rb | 40 +++++++++++++++++++ .../_save_and_continue_callback.html.erb | 3 ++ 2 files changed, 43 insertions(+) create mode 100644 app/views/refinery/blog/admin/posts/_save_and_continue_callback.html.erb diff --git a/app/controllers/refinery/blog/admin/posts_controller.rb b/app/controllers/refinery/blog/admin/posts_controller.rb index 0554d183..969b91f1 100644 --- a/app/controllers/refinery/blog/admin/posts_controller.rb +++ b/app/controllers/refinery/blog/admin/posts_controller.rb @@ -74,6 +74,38 @@ def create end end + def update + if @post.update_attributes(post_params) + flash.notice = t('refinery.crudify.updated', what: "'#{@post.title}'") + + if from_dialog? + self.index + @dialog_successful = true + render :index + else + if params[:continue_editing] =~ /true|on|1/ + if request.xhr? + render partial: 'save_and_continue_callback', + locals: save_and_continue_locals(@post) + else + redirect_to :back + end + else + redirect_back_or_default(refinery.blog_admin_posts_path()) + end + end + else + if request.xhr? + render :partial => '/refinery/admin/error_messages', :locals => { + :object => @post, + :include_object_name => true + } + else + render 'edit' + end + end + end + def delete_translation find_post @post.translations.find_by_locale(params[:locale_to_delete]).destroy @@ -95,6 +127,14 @@ def permitted_post_params ] end + def save_and_continue_locals(post) + { + new_refinery_edit_post_path: refinery.edit_blog_admin_post_path(post), + new_refinery_post_path: refinery.blog_admin_post_path(post), + new_post_path: refinery.blog_post_path(post) + } + end + protected def find_post diff --git a/app/views/refinery/blog/admin/posts/_save_and_continue_callback.html.erb b/app/views/refinery/blog/admin/posts/_save_and_continue_callback.html.erb new file mode 100644 index 00000000..b87e585f --- /dev/null +++ b/app/views/refinery/blog/admin/posts/_save_and_continue_callback.html.erb @@ -0,0 +1,3 @@ +<%= render '/refinery/message' %> +<%= hidden_field_tag 'new_action', local_assigns[:new_refinery_post_path] %> +<%= hidden_field_tag 'new_refinery_edit_page_path', local_assigns[:new_refinery_edit_post_path] %> \ No newline at end of file