From d6aadc1624c399d140fe53d468e31770ba825054 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 23 Dec 2014 10:05:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=92=8C=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=AF=BE=E7=A8=8B=E8=80=81=E5=B8=88=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/course.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 8e5609f32..0dd0d6aeb 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -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