Re: [chicagoboss] Question about Sessions and Flash Messages in Chicago Boss

224 views
Skip to first unread message

Konstantin Nikiforov

unread,
Nov 4, 2012, 12:05:12 PM11/4/12
to chica...@googlegroups.com
I think, it is a bad idea to study hi-level programming without any
basic erlang skills. It will be better to read basic erlang tutorial
before.

> so it now looks like this:
> -module(appname_my_controller, [Req, SessionID]).
> boss_flash:add(SessionID, notice, "Welcome!", "Your Session has now
> begun!").

- You've forgot to create a function ("action") and
export it. "boss_flash"-line is a code. And code must live inside
function.

- Controller action should return valid result.
http://www.chicagoboss.org/api-controller.html#return_values

-module(appname_my_controller, [Req, SessionID]
-compile(export_all).
my_action() ->
boss_flash:add(SessionID, notice, "Welcome!", "Your S...."),
ok. %% <- valid returned value

ok means "render template src/view/my/my_action.html with no
additional variables".
And now you can make a http-request to
http://.../my/my_action from your web-browser.


В Sun, 4 Nov 2012 05:36:28 -0800 (PST)
"@chrisco" <chris....@gmail.com> пишет:

> Hi,
>
> I am a beginner programmer (beginner at programming in general and
> Erlang and ChicagoBoss in particular) and am trying to understand
> Sessions and their related Flash Messages in Chicago Boss. I have
> reviewed the tutorial and the API documentation and can't figure it
> out. This is what I've done:
>
> Created headliners_app_controller.erl
> and put this as the one line in it:
>
> -module(headliners_app, [Req, SessionID]).
>
> When I run the app and use a Chrome extension ("Edit This Cookie") I
> see that a session has been created. So far so good.
>
> When I try to test/experiment with boss_flash, as described here
> http://www.chicagoboss.org/api-session.html, I everything goes to
> shit. I think (know?) I'm doing something dumb, but after trying for
> too long (embarrassed to say how long!), I can't figure it out and
> decided to ask for help, so here I am.
>
> How do I use boss_flash? I just basically want to get to a Chicago
> Boss Sessions and Flash "hello world"! Thanks.
>
> Here are further details on my beginner's folly:
>
> I added this line:
> boss_flash:add(SessionID, notice, "Welcome!", "Your Session has now
> begun!").
>
> to this file:
> headliners_app_controller.erl
>
> so it now looks like this:
> -module(appname_my_controller, [Req, SessionID]).
> boss_flash:add(SessionID, notice, "Welcome!", "Your Session has now
> begun!").
>
> I added this line to a view file:
> {% for flash in boss_flash %} {{ flash.method }} - {{ flash.title }}
> - {{ flash.message }} {% endfor %}
>
> I restarted the server with:
> ./init-dev.sh
>
> And get this error:
> Error:
> {function_clause,
> [{erlydtl_runtime,init_counter_stats,
> [undefined,undefined],
> [{file,"src/erlydtl_runtime.erl"},{line,208}]},
> {headliners_app_view_search_index_html,render_internal,4,[]},
> {headliners_app_view_search_index_html,render,2,[]},
> {boss_web_controller,render_view,6,
> [{file,"src/boss/boss_web_controller.erl"},{line,836}]},
> {boss_web_controller,execute_action,5,
> [{file,"src/boss/boss_web_controller.erl"},{line,725}]},
> {boss_web_controller,execute_action,5,
> [{file,"src/boss/boss_web_controller.erl"},{line,727}]},
> {boss_web_controller,process_request,5,
> [{file,"src/boss/boss_web_controller.erl"},{line,459}]},
> {timer,tc,3,[{file,"timer.erl"},{line,194}]}]}
>
> I tried all the combinations of moving the code to different files
> (mainly just the controller for the particular view I wanted to show
> the flash message in) and either got the same error or the server (in
> the server shell window) seems to keep looping through "starting
> development server" (or whatever the exact wording is that it uses
> when it launches).
>
> Thanks,
> Chris
>

signature.asc

Christopher Comella

unread,
Nov 4, 2012, 12:52:53 PM11/4/12
to chica...@googlegroups.com
Thanks for the reply.  I thought "boss_flash:add/4" was the function I was using and that the API documentation example was complete.  It didn't say otherwise, unless I missed it.  Yes, like I said, I am a beginner and didn't recognize what was obvious to everybody on this list who knows more than me.  

PS: Thanks for putting people down people for trying to learn, even if they are in over their head and say so.  Not everyone is as smart or experienced as you.  In fact, I suspect you'll be surprised to learn (if you can accept it is true and it works for some people), some of us learn by going playing above or skill level (way above, in some cases).

Konstantin Nikiforov

unread,
Nov 4, 2012, 1:40:14 PM11/4/12
to chica...@googlegroups.com
> some of us learn by going playing above or skill level (way above, in
> some cases).

No problem here. My assertion is connected with chicagoboss
internals.

CB using own complex erlang preprocessor - aleppo. On
error, aleppo output is very difficult to understand (for newbies).
Example output you could see in your first message:

> {function_clause,
> [{erlydtl_runtime,init_counter_stats,
> [undefined,undefined],
> [{file,"src/erlydtl_runtime.erl"},{line,208}]},
> ... ... ... ...

This output complexity is the main reason.

Standard erlang preprocessor shows much more user-friendly messages:
> Syntax error on line 2 before 'boss_flash'

So, in chicagoboss development, you will save *many* time, if you will
utilize basic erlang expirience for code syntax debugging. The
programmer's time is costy.


В Sun, 4 Nov 2012 18:52:53 +0100
Christopher Comella <chris....@gmail.com> пишет:
signature.asc

Christopher Comella

unread,
Nov 4, 2012, 1:59:15 PM11/4/12
to chica...@googlegroups.com
Ok, thanks for the additional info, understanding, and toleration :)

Tim McNamara

unread,
Nov 6, 2012, 4:01:30 AM11/6/12
to chica...@googlegroups.com
Hey Christopher,

i just wanted to reassure you that you are very welcome to ask any and all questions here :) I think you just hit some cross-cultural differences. The Chicago Boss community is made up of a very high proportion of programmers who are new to Erlang. You may be the first I've seen who is new to programming in general though. Good luck!

We are also an extremely culturally diverse community. I expect that the minority have English as their native language. If people seem less sensitive than you expect, it's very unlikely to be because they're intending to be perceived in that way.

Good luck with your progress!

Tim McNamara
Professional \\  paperlessprojects.com
Personal \\  @timClicks  |  timmcnamara.co.nz



--
 
 

Christopher Comella

unread,
Nov 6, 2012, 4:22:55 AM11/6/12
to chica...@googlegroups.com
Thanks, Tim.  And thank you, Konstantin, for your original reply.  I'm still having trouble, but might just give up on that problem for now and move on to other aspects.  That said, if someone were to send me a working Flash Message "hello world," or put on one the Wiki or some other place where everyone who finds and tries Chicago Boss could benefit, I would not complain!  Cheers and thank you, Chicago Boos folks!

-Chris

--
 
 

Evan Miller

unread,
Nov 6, 2012, 10:39:02 AM11/6/12
to ChicagoBoss
You need to pass the flash messages into the view from the controller:

Messages = boss_flash:get_and_clear(SessionID)
{ok, [{flash_messages, Messages}]}

View:

{% for message in flash_messages %} ... {% endfor %}

See here for a list of variables that the views can access "for free":


Everything else must be passed in explicitly.

Graeme Defty

unread,
Nov 7, 2012, 2:52:43 AM11/7/12
to chica...@googlegroups.com
Evan,

This reminds me of an earlier conversation regarding an option to display all variables passed to the view for debugging purposes.

It occurs to me this could be done as a "for free" variable (e.g. _data)

Sounds easy to do. Is it practical?

g

_____________________________________________________________

--
 
 

Kai Janson

unread,
Nov 7, 2012, 9:26:04 AM11/7/12
to chica...@googlegroups.com
You can do that by using {{_session}} in the view for the session variables, but for variables stemming off the controller, that'd be great ... 

--Kai


--
 
 

Christopher Comella

unread,
Nov 7, 2012, 4:15:46 AM11/7/12
to chica...@googlegroups.com
If this is something a lot of newcomers might be interested in and might have some difficulty with, maybe it is a candidate for addition to the ChicagoBoss documentation, such as showing some real, working sample code.  Maybe :)

--
 
 

Evan Miller

unread,
Nov 7, 2012, 12:00:42 PM11/7/12
to ChicagoBoss
Well, actually I was wrong -- apparently "boss_flash" is automatically provided, at least in the latest GitHub version. So that example code should work if you run the latest code. Shows what I know.

Here's a patch that puts a copy of all the variables into "_vars". You can iterate like

{% for key, value in _vars %}
...

Graeme Defty

unread,
Nov 8, 2012, 2:24:33 AM11/8/12
to chica...@googlegroups.com

Beautiful!

____________________________________

--
 
 

Reply all
Reply to author
Forward
0 new messages