From 48ddc999557a8eda671d86c666c8ac5661d047fc Mon Sep 17 00:00:00 2001 From: cktricky Date: Wed, 12 Mar 2014 17:45:08 -0400 Subject: [PATCH] some basic api functionality with a few gotchas --- app/controllers/api/v1/users_controller.rb | 12 ++++++++++-- app/models/user.rb | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index a23daf3..d995abb 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -5,9 +5,17 @@ class Api::V1::UsersController < ApplicationController before_filter :extrapolate_user respond_to :json - + def index - respond_with @user + # We removed the .as_json code from the model, just seemed like extra work. + # dunno, maybe useful at a later time? + #respond_with @user.admin ? User.all.as_json : @user.as_json + + respond_with @user.admin ? User.all : @user + end + + def show + respond_with @user.as_json end private diff --git a/app/models/user.rb b/app/models/user.rb index 2af7dc2..7705a10 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,6 +37,13 @@ class User < ActiveRecord::Base def full_name "#{self.first_name} #{self.last_name}" end + +=begin + # Instead of the entire user object being returned, we can use this to filter. + def as_json + super(only: [:user_id, :email, :first_name, :last_name]) + end +=end private