some basic api functionality with a few gotchas

This commit is contained in:
cktricky
2014-03-12 17:45:08 -04:00
parent ed800fd601
commit 48ddc99955
2 changed files with 17 additions and 2 deletions
+9 -1
View File
@@ -7,7 +7,15 @@ class Api::V1::UsersController < ApplicationController
respond_to :json respond_to :json
def index 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 end
private private
+7
View File
@@ -38,6 +38,13 @@ class User < ActiveRecord::Base
"#{self.first_name} #{self.last_name}" "#{self.first_name} #{self.last_name}"
end 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 private
def self.authenticate(email, password) def self.authenticate(email, password)