From 50171effadc7eab3ab029061ed0f10f271f3f9c8 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Fri, 1 Feb 2013 03:58:26 -0700 Subject: [PATCH] Allowing JSON --- app/controllers/macs_controller.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/macs_controller.rb b/app/controllers/macs_controller.rb index 043ecae..75213e4 100644 --- a/app/controllers/macs_controller.rb +++ b/app/controllers/macs_controller.rb @@ -13,13 +13,23 @@ def index # De-dupe users for the public if can? :update, Mac then @active_macs = Mac.where("macs.active = ? AND (macs.hidden IS NULL OR macs.hidden = ?)", true, false).includes(:user).order("users.name ASC") - else + elsif user_signed_in? then @active_macs = Mac.where("macs.active = ? AND (macs.hidden IS NULL OR macs.hidden = ?)", true, false).includes(:user).order("users.name ASC").group("users.name") + else + @active_macs = Mac.select("mac, note, user_id").where("macs.active = ? AND (macs.hidden IS NULL OR macs.hidden = ?)", true, false).joins(:user).order("users.name ASC").group("users.name") end @hidden_macs = Mac.where("macs.active = ? AND macs.hidden = ?", true, true).order("note ASC") @all_macs = Mac.find(:all, :order => "LOWER(mac)") + + respond_to do |format| + format.html + format.json { + @filtered_macs = Mac.select("macs.mac, users.name").where("macs.active = ? AND (macs.hidden IS NULL OR macs.hidden = ?)", true, false).joins(:user) + render :json => @filtered_macs + } + end end # GET /macs/1