From c599723096108bba0f626412a7b92371e5e8ac12 Mon Sep 17 00:00:00 2001 From: Bryan Larsen Date: Tue, 8 Dec 2009 15:46:48 -0500 Subject: [PATCH] [#575 state:resolved] move flash messages inside block replacement --- hobo/CHANGES.txt | 7 +++++++ hobo/lib/hobo/model_controller.rb | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/hobo/CHANGES.txt b/hobo/CHANGES.txt index 04919d9..743f4d3 100644 --- a/hobo/CHANGES.txt +++ b/hobo/CHANGES.txt @@ -46,6 +46,13 @@ The new `` tag differs from `` in that: You will have to ensure that your hobo-rapid.js and clean.css files are updated in your application. +The flash message "The was created successfully" will now not +be displayed if you pass a customized block to `hobo_create`. Similar +changes were made to `hobo_update` and `hobo_destroy`. This change +does not affect the default behaviour of Hobo, just allows those who +customize their controller behaviour to have finer control over their +customizations. + === Hobo 0.9.101/0.9.102 (AKA 1.0.BROWN_PAPER_BAG) === Yes, that was embarrassing. How the test suite failed to catch that diff --git a/hobo/lib/hobo/model_controller.rb b/hobo/lib/hobo/model_controller.rb index 2d5c6b4..b48d19e 100644 --- a/hobo/lib/hobo/model_controller.rb +++ b/hobo/lib/hobo/model_controller.rb @@ -562,12 +562,13 @@ module Hobo def create_response(new_action, options={}, &b) - flash_notice (ht( :"#{@this.class.name.pluralize.underscore}.messages.create.success", :default=>["The #{@this.class.name.titleize.downcase} was created successfully"])) if valid? - - response_block(&b) or + unless response_block(&b) if valid? respond_to do |wants| - wants.html { redirect_after_submit(options) } + wants.html { + flash_notice(ht( :"#{@this.class.name.pluralize.underscore}.messages.create.success", :default=>["The #{@this.class.name.titleize.downcase} was created successfully"])) + redirect_after_submit(options) + } wants.js { hobo_ajax_response || render(:nothing => true) } end else @@ -580,6 +581,7 @@ module Hobo )} end end + end end @@ -599,13 +601,11 @@ module Hobo def update_response(in_place_edit_field=nil, options={}, &b) - - flash_notice (ht(:"#{@this.class.name.pluralize.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.name.titleize.downcase} were saved"])) if valid? - - response_block(&b) or + unless response_block(&b) if valid? respond_to do |wants| wants.html do + flash_notice(ht(:"#{@this.class.name.pluralize.underscore}.messages.update.success", :default=>["Changes to the #{@this.class.name.titleize.downcase} were saved"])) redirect_after_submit options end wants.js do @@ -631,6 +631,7 @@ module Hobo ) } end end + end end @@ -638,17 +639,20 @@ module Hobo options = args.extract_options! self.this ||= args.first || find_instance this.user_destroy(current_user) - flash_notice ht( :"#{model.name.pluralize.underscore}.messages.destroy.success", :default=>["The #{model.name.titleize.downcase} was deleted"]) destroy_response(options, &b) end def destroy_response(options={}, &b) - response_block(&b) or + unless response_block(&b) respond_to do |wants| - wants.html { redirect_after_submit(this, true, options) } + wants.html do + flash_notice(ht(:"#{model.name.pluralize.underscore}.messages.destroy.success", :default=>["The #{model.name.titleize.downcase} was deleted"])) + redirect_after_submit(this, true, options) + end wants.js { hobo_ajax_response || render(:nothing => true) } end + end end -- 1.6.3.3