Permalink
Browse files

added relations to json interface of 'show' for apps

  • Loading branch information...
1 parent b3abbd7 commit 4b9c69c3900805c8f31740bc8389fb5e4be8f90e @igmcdowell igmcdowell committed Dec 29, 2011
Showing with 29 additions and 3 deletions.
  1. +28 −3 app/controllers/apps_controller.rb
  2. +1 −0 app/models/app.rb
@@ -13,11 +13,36 @@ def index
# GET /apps/1
# GET /apps/1.json
def show
- @app = App.find(params[:id])
-
+ @app = App.includes(:prices).find(params[:id])
+
respond_to do |format|
format.html # show.html.erb
- format.json { render json: @app }
+ format.json {
+ # the ugly syntax below is the only way I could get this to work. See this thread: http://www.ruby-forum.com/topic/132229
+ render json: @app.to_json(
+ :include => {
+ :genres => {
+ :only => :name
+ },
+ :genre_codes => {
+ :only => :genre
+ },
+ :ipad_screenshot_urls => {
+ :only => :url
+ },
+ :language_codes => {
+ :only => :language
+ },
+ :screenshot_urls => {
+ :only => :url
+ },
+ :supported_devices => {
+ :only => :device
+ }
+ })
+
+
+ }
end
end
View
@@ -10,6 +10,7 @@ class App < ActiveRecord::Base
after_create :add_price_history
after_save :check_price_change
before_save :truncate_values
+
def self.recent_price_drops(numprices)
includes(:prices).where("prices.end_date" => nil).where("prices.is_decrease" => true).order("prices.created_at desc").limit(numprices)

0 comments on commit 4b9c69c

Please sign in to comment.