Question

I'm connecting a to an Extrenal Server. After going through proper authorization process I get the reponse JSON object.

I'm now trying to display this JSON in view.

Here what I have done so far.

My first Action (which is called from Javascript that initiates Authorization process and fetches the data):

connect_external('POST',[])->
    ExternalData = get_external_data(),
    io:format("External Data Summary for put~n~p~n", [ExternalData]),
    put(?MY_EXTERNAL_DATA, ExternalData).

In the second action (Javascript redirection to the display page) :

my_own_data('GET',[])->
    MyData = get(?MY_EXTERNAL_DATA),
    io:format("External Data Summary for get~n~p~n", [MyData]),
    {ok, [{mydata, MyData}]}.

My aim is to display the JSON object in the view. But I don't see it. It's because get() call fails (put is successful as I can print the JSON) and in console I get:

External Data Summary for get
undefined

I'm very new to ChicagoBoss/Erlang. Any help would really appreciated. Should I use process dictionary at all? If not what is the altenative approach?

Was it helpful?

Solution

As pointed out by Anthony Kong, I have solved this problem using boss_session:set_session_data(...) and boss_session:get_session_data().

OTHER TIPS

Yes answer of raich is correct, looks like sessions do not work in production in this case, though they work in development. A bit more about usage of these methods -

-module(your_controller, [Req, SessionID]). 
.....
boss_session:set_session_data(SessionID, filter_start_date, Req:post_param("start_date")),
boss_session:get_session_data(SessionID, filter_start_date)
boss_session:remove_session_data(SessionID, filter_start_date)
.....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top