Skip to content

Commit

Permalink
reference responses as hash keys
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Apr 4, 2016
1 parent 9769d5d commit 603e45b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/controllers/radiant/admin/pages_controller.rb
Expand Up @@ -10,7 +10,7 @@ def message
end

responses do |r|
r.plural.js do
r[:plural].js do
@level = params[:level].to_i
@template_name = 'index'
self.models = Page.find(params[:page_id]).children.all
Expand Down
31 changes: 15 additions & 16 deletions app/controllers/radiant/admin/resource_controller.rb
Expand Up @@ -27,32 +27,31 @@ def self.responses
responses do |r|
# Equivalent respond_to block for :plural responses:
# respond_to do |wants|
# wants.xml { render xml: models }
# wants.json { render json: models }
# wants.any
# end
r.plural.publish(:xml, :json) { render format_symbol => models }
r[:plural].publish(:xml, :json) { render format_symbol => models }

r.singular.publish(:xml, :json) { render format_symbol => model }
r.singular.default { redirect_to edit_model_path if action_name == "show" }
r[:singular].publish(:xml, :json) { render format_symbol => model }
r[:singular].default { redirect_to edit_model_path if action_name == "show" }

r.not_found.publish(:xml, :json) { head :not_found }
r.not_found.default { announce_not_found; redirect_to action: "index" }
r[:not_found].publish(:xml, :json) { head :not_found }
r[:not_found].default { announce_not_found; redirect_to action: "index" }

r.invalid.publish(:xml, :json) { render format_symbol => model.errors, status: :unprocessable_entity }
r.invalid.default { announce_validation_errors; render action: template_name }
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 }
r[:stale].publish(:xml, :json) { head :conflict }
r[:stale].default { announce_update_conflict; render action: template_name }

r.create.publish(:xml, :json) { render format_symbol => model, status: :created, location: url_for(format: format_symbol, id: model) }
r.create.default { redirect_to continue_url(params) }
r[:create].publish(:xml, :json) { render format_symbol => model, status: :created, location: url_for(format: format_symbol, id: model) }
r[:create].default { redirect_to continue_url(params) }

r.update.publish(:xml, :json) { head :ok }
r.update.default { redirect_to continue_url(params) }
r[:update].publish(:xml, :json) { head :ok }
r[:update].default { redirect_to continue_url(params) }

r.destroy.publish(:xml, :json) { head :deleted }
r.destroy.default { redirect_to continue_url(params) }
r[:destroy].publish(:xml, :json) { head :deleted }
r[:destroy].default { redirect_to continue_url(params) }
end

def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/radiant/application_controller.rb
Expand Up @@ -2,7 +2,7 @@
require 'login_system'

module Radiant
class ApplicationController < ::ApplicationController
class ApplicationController < ::ActionController::Base
include ::LoginSystem

before_filter :set_timezone
Expand Down
2 changes: 1 addition & 1 deletion lib/radiant/resource_responses.rb
Expand Up @@ -3,7 +3,7 @@ module Radiant
module ResourceResponses
module InstanceMethods
def response_for(action)
responses = self.class.responses.send(action)
responses = self.class.responses.send(:[], action)
respond_to do |wants|
responses.each_format do |f, format_block|
if format_block
Expand Down

0 comments on commit 603e45b

Please sign in to comment.