Skip to content

Commit

Permalink
Merge pull request #16 from cbus-sea-lions-2015/add-includes-librarie…
Browse files Browse the repository at this point in the history
…s-show

add mechanics and categories to libraries#show
  • Loading branch information
mdmartinez committed Apr 20, 2015
2 parents 3c7c9f8 + 4df4549 commit b012e9f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ def index
end

def show
all_games = Library.find_by(bgg_username: params[:id]).games
render json: all_games.to_json
all_games = Library.find_by(bgg_username: params[:id]).games.includes(:categories,:mechanics)

json_games = all_games.map do |game|
JSON::parse(game.to_json).merge({
"mechanics"=> game.mechanics.map(&:name),
"categories"=> game.categories.map(&:name),
})
end

render json: json_games.to_json
end

def create
Expand Down

0 comments on commit b012e9f

Please sign in to comment.