Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_controller
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
simple_controller
Commits
9c35be54
Commit
9c35be54
authored
Aug 12, 2023
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add response_view_path to simple_controller base_controller
parent
bc99ead9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
base_controller.rb
lib/simple_controller/base_controller.rb
+16
-6
No files found.
lib/simple_controller/base_controller.rb
View file @
9c35be54
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment