Kai,
Thank you so much for trying to help me!
if I navigate to localhost:8001/status/customers I crash
I know that the before_ is getting results (I was able to print them out before returning them), and I know that I crash before the first line of the customers('GET', [], SUser) function.
My controller code looks like this (the before_ is the last line of code).
-module(ehc_server_status_controller, [Req]).
-compile(export_all).
customers('GET', [], SUser) ->
Customers = boss_db:find(customer, []),
Selected = hd(Customers),
SelectedId = Selected:id(),
Timestamp = boss_mq:now("changes"),
R = boss_db:count(facility,[{status, equals, "red"}]),
Y = boss_db:count(facility,[{status, equals, "yellow"}]),
{ok, [{customers, Customers},{selected, Selected},{selected_id, SelectedId},
{facilities, []}, {timestamp, Timestamp},{reds, R},
{yellows, Y},{s_user, SUser}]};
customers('GET', ["since", LastTimeStamp], SUser) ->
{ok, Timestamp, Changes} = boss_mq:pull("changes", list_to_integer(LastTimeStamp)),
Customers = [Customer || {customer, Customer} <- Changes],
Facilities = [Facility || {facility, Facility} <- Changes],
R = boss_db:count(facility,[{status, equals, "red"}]),
Y = boss_db:count(facility,[{status, equals, "yellow"}]),
{json, [{customers, Customers},{facilities, Facilities}, {timestamp, Timestamp},
{reds, R},{yellows, Y}, {s_user, SUser}]};
customers('GET', ["facilities", CustId], SUser) ->
Facilities = boss_db:find(facility, [customer_id, equals, CustId]),
[Customer] = boss_db:find(customer, [id, equals, CustId]),
{render_other, [{action, "facilities"}],[{facilities, Facilities},{customer, Customer}, {s_user, SUser}]}.
facility('GET', [LastTimeStamp]) ->
{ok, Timestamp, Facilities} = boss_mq:pull("facility", list_to_integer(LastTimeStamp)),
R = boss_db:find(facility,[{status, equals, "red"}]),
Y = boss_db:find(facility,[{status, equals, "yellow"}]),
{json, [{facilities, Facilities},{f_timestamp, Timestamp},
{reds, length(R)},{yellows, length(Y)}]}.
response('GET', [RespId]) ->
[R] = boss_db:find(response, [id, equals, RespId]),
{json, [{response, R}]}.
responses('GET', [FacId]) ->
[F] = boss_db:find(facility, [id, equals, FacId]),
R = F:responses(),
Fs = boss_db:find(failures, [facility_id, equals, F:id()]),
{ok, [{facility, F}, {responses, R}, {failures, Fs}]}.
pull('GET',["facilities", CustId]) ->
F = boss_db:find(facility,[{customer_id, equals, CustId}]),
{json, [{facilities,F}]};
pull('GET', [LastTimestamp]) ->
{ok, Timestamp, Responses} = boss_mq:pull("new-response",
list_to_integer(LastTimestamp)),
{json, [{timestamp, Timestamp}, {responses, Responses}]}.
before_("customers",_, _)->
user_lib:require_login(Req).