app/controllers/admin/resource_controller.rb in radiant-0.7.2 vs app/controllers/admin/resource_controller.rb in radiant-0.8.0

- old
+ new

@@ -19,12 +19,15 @@ # wants.any # end r.plural.publish(:xml, :json) { render format_symbol => models } r.singular.publish(:xml, :json) { render format_symbol => model } + + r.not_found.publish(:xml, :json) { head :not_found } + r.not_found.default { announce_not_found; redirect_to continue_url(params) } - r.invalid.publish(:xml, :json) { render format_symbol => model.errors, :status => :unprocessible_entity } + r.invalid.publish(:xml, :json) { render format_symbol => model.errors, :status => :unprocessable_entity } r.invalid.default { announce_validation_errors; render :action => template_name } r.stale.publish(:xml, :json) { head :conflict } r.stale.default { announce_update_conflict; render :action => template_name } @@ -72,25 +75,16 @@ case exception when ActiveRecord::RecordInvalid response_for :invalid when ActiveRecord::StaleObjectError response_for :stale + when ActiveRecord::RecordNotFound + response_for :not_found else super end end - - def template_name - case self.action_name - when 'new','create' - 'new' - when 'edit', 'update' - 'edit' - when 'remove', 'destroy' - 'remove' - end - end def model_class self.class.model_class end @@ -153,17 +147,21 @@ end def announce_removed flash[:notice] = "#{humanized_model_name} has been deleted." end + + def announce_not_found + flash[:notice] = "#{humanized_model_name} could not be found." + end def announce_update_conflict flash.now[:error] = "#{humanized_model_name} has been modified since it was last loaded. Changes cannot be saved without potentially losing data." end def clear_model_cache - cache.clear + Radiant::Cache.clear if defined?(Radiant::Cache) end def format_symbol format.to_sym end @@ -171,10 +169,10 @@ def format params[:format] || 'html' end # Assist with user agents that cause improper content-negotiation - warn "Remove default HTML format, Accept header no longer used. (#{__FILE__}: #{__LINE__})" if Rails.version !~ /^2\.1/ + # warn "Remove default HTML format, Accept header no longer used. (#{__FILE__}: #{__LINE__})" if Rails.version !~ /^2\.1/ def populate_format params[:format] ||= 'html' unless request.xhr? end end