diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index f945e41..aecebb2 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -64,6 +64,7 @@ class CmsController < MyProfileController end def edit + @success_back_to = params[:success_back_to] @article = profile.articles.find(params[:id]) @parent_id = params[:parent_id] @type = params[:type] || @article.class.to_s @@ -77,7 +78,7 @@ class CmsController < MyProfileController if @article.update_attributes(params[:article]) if !continue if @article.content_type.nil? || @article.image? - redirect_to @article.view_url + success_redirect else redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent end @@ -89,6 +90,7 @@ class CmsController < MyProfileController def new # FIXME this method should share some logic wirh edit !!! + @success_back_to = params[:success_back_to] # user must choose an article type first @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id] @@ -133,7 +135,7 @@ class CmsController < MyProfileController if continue redirect_to :action => 'edit', :id => @article else - redirect_to @article.view_url + success_redirect end return end @@ -385,5 +387,13 @@ class CmsController < MyProfileController true end + def success_redirect + if !@success_back_to.blank? + redirect_to @success_back_to + else + redirect_to @article.view_url + end + end + end diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index 566ae87..263da2c 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -9,6 +9,8 @@ <%= hidden_field_tag('back_to', @back_to) %> + <%= hidden_field_tag('success_back_to', @success_back_to) %> + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> <% if environment.is_portal_community?(profile) %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 5b0fb39..dc8a403 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1688,6 +1688,17 @@ class CmsControllerTest < ActionController::TestCase :attributes => { :value => article.id.to_s }} end + should 'go back to specified url when saving with success' do + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' }, :success_back_to => '/' + assert_redirected_to '/' + end + + should 'redirect back to specified url when edit with success' do + article = @profile.articles.create!(:name => 'myarticle') + post :edit, :profile => 'testinguser', :id => article.id, :success_back_to => '/' + assert_redirected_to '/' + end + protected # FIXME this is to avoid adding an extra dependency for a proper JSON parser. -- libgit2 0.21.2