add RequestStore gem, support universal only param for api endpoints (fixes #4068)
This commit is contained in:
@@ -149,12 +149,25 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
|
||||
def as_json(options = {})
|
||||
options ||= {}
|
||||
|
||||
options[:except] ||= []
|
||||
options[:except] += hidden_attributes
|
||||
|
||||
options[:methods] ||= []
|
||||
options[:methods] += method_attributes
|
||||
|
||||
if !options.key?(:only) && RequestStore.exist?(:only_param)
|
||||
options[:only] = RequestStore[:only_param]
|
||||
end
|
||||
|
||||
if options[:only].is_a?(String)
|
||||
options[:only] = options[:only].split(/,/)
|
||||
end
|
||||
|
||||
if options[:only]
|
||||
options[:methods] = options[:methods] & options[:only]
|
||||
end
|
||||
|
||||
super(options)
|
||||
end
|
||||
|
||||
@@ -167,6 +180,18 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
options[:methods] ||= []
|
||||
options[:methods] += method_attributes
|
||||
|
||||
if !options.key?(:only) && RequestStore.exist?(:only_param)
|
||||
options[:only] = RequestStore[:only_param]
|
||||
end
|
||||
|
||||
if options[:only].is_a?(String)
|
||||
options[:only] = options[:only].split(/,/)
|
||||
end
|
||||
|
||||
if options[:only]
|
||||
options[:methods] = options[:methods] & options[:only]
|
||||
end
|
||||
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user