OSDN Git Service

Format JSON output
authoreagletmt <eagletmt@gmail.com>
Fri, 15 Jun 2012 06:26:43 +0000 (15:26 +0900)
committereagletmt <eagletmt@gmail.com>
Fri, 15 Jun 2012 06:53:51 +0000 (15:53 +0900)
CutenServer/app/models/jar.rb
CutenServer/app/models/lecture.rb
CutenServer/app/models/task.rb
CutenServer/app/models/teacher.rb
CutenServer/config/application.rb
CutenServer/extras/json_without_timestamps.rb [new file with mode: 0644]

index 927e7c1..d3fa6a5 100644 (file)
@@ -1,4 +1,9 @@
 class Jar < ActiveRecord::Base
   belongs_to :task
   attr_accessible :name, :revision
+
+  include JsonWithoutTimestamps
+  def as_json(options = {})
+    super options.merge({:except => [:task_id]})
+  end
 end
index e75832a..7e35ab8 100644 (file)
@@ -2,4 +2,9 @@ class Lecture < ActiveRecord::Base
   belongs_to :teacher
   has_many :tasks
   attr_accessible :name
+
+  include JsonWithoutTimestamps
+  def as_json(options = {})
+    super options.merge({:methods => [:task_ids, :teacher], :except => [:teacher_id]})
+  end
 end
index 618d3bf..b94ac88 100644 (file)
@@ -2,4 +2,9 @@ class Task < ActiveRecord::Base
   belongs_to :lecture
   has_one :jar
   attr_accessible :name
+
+  include JsonWithoutTimestamps
+  def as_json(options = {})
+    super options.merge({:methods => [:jar], :except => [:lecture_id]})
+  end
 end
index 5519d58..f64b22b 100644 (file)
@@ -1,4 +1,6 @@
 class Teacher < ActiveRecord::Base
   has_many :lectures
   attr_accessible :name
+
+  include JsonWithoutTimestamps
 end
index 2cda3f3..6f25f7a 100644 (file)
@@ -16,7 +16,7 @@ module CutenServer
     # -- all .rb files in that directory are automatically loaded.
 
     # Custom directories with classes and modules you want to be autoloadable.
-    config.autoload_paths += %W(#{config.root}/extras)
+    config.autoload_paths += %W(#{config.root}/extras)
 
     # Only load the plugins named here, in the order given (default is alphabetical).
     # :all can be used as a placeholder for all plugins not explicitly named.
diff --git a/CutenServer/extras/json_without_timestamps.rb b/CutenServer/extras/json_without_timestamps.rb
new file mode 100644 (file)
index 0000000..a4c2fee
--- /dev/null
@@ -0,0 +1,5 @@
+module JsonWithoutTimestamps
+  def as_json(options = {})
+    super options.merge({:except => (options[:except] || []) + [:created_at, :updated_at]})
+  end
+end