微信BUG修改

This commit is contained in:
yuanke 2016-11-09 14:59:10 +08:00
parent aa66134c24
commit a9c019e3a8
2 changed files with 40 additions and 1 deletions

View File

@ -24,7 +24,7 @@ gem 'rubyzip'
gem 'delayed_job_active_record'#, :group => :production
gem 'daemons'
gem 'grape', '~> 0.9.0'
gem 'grape-entity', '= 0.4.5'
gem 'grape-entity'
gem 'rack-cors', :require => 'rack/cors'
gem 'seems_rateable', '~> 1.0.13'
gem 'rails', '~> 3.2'

View File

@ -175,3 +175,42 @@ module ActionController
end
end
end
module Grape
class Entity
def self.expose(*args, &block)
options = merge_options(args.last.is_a?(Hash) ? args.pop : {})
if args.size > 1
fail ArgumentError, 'You may not use the :as option on multi-attribute exposures.' if options[:as]
fail ArgumentError, 'You may not use block-setting on multi-attribute exposures.' if block_given?
end
fail ArgumentError, 'You may not use block-setting when also using format_with' if block_given? && options[:format_with].respond_to?(:call)
options[:proc] = block if block_given? && block.parameters.any?
@nested_attributes ||= []
args.each do |attribute|
unless @nested_attributes.empty?
orig_attribute = attribute.to_sym
attribute = "#{@nested_attributes.last}__#{attribute}"
nested_attribute_names_hash[attribute.to_sym] = orig_attribute
options[:nested] = true
nested_exposures_hash[@nested_attributes.last.to_sym] ||= {}
nested_exposures_hash[@nested_attributes.last.to_sym][attribute.to_sym] = options
end
exposures[attribute.to_sym] = options
# Nested exposures are given in a block with no parameters.
if block_given? && block.parameters.empty?
@nested_attributes << attribute
block.call
@nested_attributes.pop
end
end
end
end
end