Commit 9c35be54 by liyijie

feat: add response_view_path to simple_controller base_controller

parent bc99ead9
...@@ -29,17 +29,17 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -29,17 +29,17 @@ class SimpleController::BaseController < ::InheritedResources::Base
end end
def index!(options = {}, &block) def index!(options = {}, &block)
options = { template: "#{self.class.view_path}/index" }.merge options options = { template: "#{response_view_path}/index" }.merge options
super(options, &block) super(options, &block)
end end
def show!(options = {}, &block) def show!(options = {}, &block)
options = { template: "#{self.class.view_path}/show" }.merge options options = { template: "#{response_view_path}/show" }.merge options
super(options, &block) super(options, &block)
end end
def create!(options = {}, &block) def create!(options = {}, &block)
options = { template: "#{self.class.view_path}/show", status: 201 }.merge options options = { template: "#{response_view_path}/show", status: 201 }.merge options
super(options, &block) super(options, &block)
end end
...@@ -47,7 +47,7 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -47,7 +47,7 @@ class SimpleController::BaseController < ::InheritedResources::Base
# 可以传入resource_params进行方法复用 # 可以传入resource_params进行方法复用
_resource_params = options.delete(:resource_params) _resource_params = options.delete(:resource_params)
_update_params = _resource_params.present? ? [_resource_params] : resource_params _update_params = _resource_params.present? ? [_resource_params] : resource_params
options = { template: "#{self.class.view_path}/show", status: 201 }.merge options options = { template: "#{response_view_path}/show", status: 201 }.merge options
object = resource object = resource
...@@ -106,6 +106,14 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -106,6 +106,14 @@ class SimpleController::BaseController < ::InheritedResources::Base
protected protected
def response_view_path
if params[:ta_templates].present? && defined?(Forms::Template)
'ta_records'
else
self.class.view_path
end
end
class << self class << self
attr_reader :view_path attr_reader :view_path
...@@ -165,12 +173,12 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -165,12 +173,12 @@ class SimpleController::BaseController < ::InheritedResources::Base
end end
def respond_resource(options: {}) def respond_resource(options: {})
options = { template: "#{self.class.view_path}/show", status: 201 }.merge options options = { template: "#{response_view_path}/show", status: 201 }.merge options
respond_with(*with_chain(resource), options) respond_with(*with_chain(resource), options)
end end
def respond_collection(options: {}) def respond_collection(options: {})
options = { template: "#{self.class.view_path}/index" }.merge options options = { template: "#{response_view_path}/index" }.merge options
respond_with(*with_chain(collection), options) respond_with(*with_chain(collection), options)
end end
...@@ -187,6 +195,7 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -187,6 +195,7 @@ class SimpleController::BaseController < ::InheritedResources::Base
} }
authorize_if_policy_class policy_info, "#{action_name}?" authorize_if_policy_class policy_info, "#{action_name}?"
instance_variable_set("@#{resource_instance_name}", resource) instance_variable_set("@#{resource_instance_name}", resource)
@ta_record = resource
end end
def set_collection_ivar(collection) def set_collection_ivar(collection)
...@@ -201,6 +210,7 @@ class SimpleController::BaseController < ::InheritedResources::Base ...@@ -201,6 +210,7 @@ class SimpleController::BaseController < ::InheritedResources::Base
} }
authorize_if_policy_class policy_info, "#{action_name}?" authorize_if_policy_class policy_info, "#{action_name}?"
instance_variable_set("@#{resource_collection_name}", collection) instance_variable_set("@#{resource_collection_name}", collection)
@ta_records = collection
end end
def association_chain def association_chain
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment