搜索和列表中的课程老师输出一致

This commit is contained in:
guange 2014-12-23 10:05:29 +08:00
parent 8fe5fee0f0
commit d6aadc1624
1 changed files with 15 additions and 6 deletions

View File

@ -3,14 +3,17 @@ module Mobile
class Course < Grape::Entity
def self.course_expose(field)
expose field do |f,opt|
o = nil
o = f.img_url if f.respond_to?(:img_url)
c = nil
if f.is_a? ::Course
o = f.send(field) if f.respond_to?(field)
c = f
else
f[:course][field] || f[:course].__send__(field)
c = f[:course]
end
if field == :img_url
f.img_url if f.respond_to?(:img_url)
else
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
end
o
end
end
course_expose :img_url
@ -39,7 +42,13 @@ module Mobile
course_expose :term
course_expose :time
course_expose :updated_at
course_expose :teacher
expose :teacher, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Course
c.teacher
else
c[:course].teacher
end
end
end
end
end