Printing floats with Erlydtl

61 views
Skip to first unread message

Guido Rumi

unread,
Feb 24, 2014, 10:30:55 AM2/24/14
to chica...@googlegroups.com
Hi!

I'm having this beginner problem, I've thought of dirty hacks but I feel like I'm missing something.

If I try to print a float stored in a db with {{ mov.in }} in my view, CB crashes with lots of errors and warnings like 
[error] gen_server boss_web terminated with reason: no case clause matching error in boss_load:'-load_views_inner/3-fun-1-'/5 line 408

I have to make some arithmetic operations and print them in my website. I'm using David's fork https://github.com/davidw/ChicagoBoss

Does anyone know an easy way to solve this? 

I've found this patch but I'm not sure what to do with it.

Thanks for your time

Fredrik de Vibe

unread,
Feb 24, 2014, 1:16:00 PM2/24/14
to chica...@googlegroups.com
Guido Rumi <guido...@gmail.com> writes:

> Hi!
>
> I'm having this beginner problem, I've thought of dirty hacks but I feel
> like I'm missing something.
>
> If I try to print a float stored in a db with {{ mov.in }} in my view, CB
> crashes with lots of errors and warnings like
> [error] gen_server boss_web terminated with reason: no case clause matching
> error in boss_load:'-load_views_inner/3-fun-1-'/5 line 408

This should not be a problem, and I also tested with David's fork to
ascertain this, using the mock db backend (the default).

So, there's something else awry, can you provide more details? What db
backend do you use? Which erlang version? Can you provide the code in
question (controller action, model and view (at least the relevant
part))?

Also, try to print the number in the console, using

io:format("~p~n", [Value])

to ensure that it is what you think it is.

> I have to make some arithmetic operations and print them in my website. I'm
> using David's fork https://github.com/davidw/ChicagoBoss
>
> Does anyone know an easy way to solve this?
>
> I've found this patch <https://code.google.com/p/erlydtl/issues/detail?id=6>but I'm not sure what to do with it.

That is _old_, and it hardly looks relevant. erlydtl lives on github
now.

> Thanks for your time


- Fredrik

Guido Rumi

unread,
Feb 24, 2014, 1:36:59 PM2/24/14
to chica...@googlegroups.com
Sure :D

Im using OTP R16B03-1 with the mock default db.

src/model/movement.erl:

-module(movement, [Id, Description::string(),In::float(),Out::float()]).
-compile(export_all).


src/controller_orillas_balance_controller.erl

-module(orillas_balance_controller, [Req]).
-compile(export_all).

sheet('GET', []) ->

    Movements = boss_db:find(movement, []),
     {ok, [{movements, Movements}]}.

src/view/balance/sheet.html

..snip...

 <td>{{ mov.id }}</td>

...snip...

works fine, but 

 <td>{{ mov.in }}</td>

crashes CB.






--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/ygnmwqgkz89r.fsf%40rubin.ifi.uio.no.

Guido Rumi

unread,
Feb 24, 2014, 1:42:49 PM2/24/14
to chica...@googlegroups.com
Sorry about that typo in controller's path
src/controller/orillas_balance_controller.erl

Fredrik de Vibe

unread,
Feb 24, 2014, 1:45:55 PM2/24/14
to chica...@googlegroups.com
Guido Rumi <guido...@gmail.com> writes:

> Sure :D
>
> Im using OTP R16B03-1 with the mock default db.
>
> *src/model/movement.erl:*
>
> -module(movement, [Id, Description::string(),In::float(),Out::float()]).
> -compile(export_all).
>
>
> *src/controller_orillas_balance_controller.erl*
>
> -module(orillas_balance_controller, [Req]).
> -compile(export_all).
>
> sheet('GET', []) ->
>
> Movements = boss_db:find(movement, []),
> {ok, [{movements, Movements}]}.
>
> *src/view/balance/sheet.html*
>
> ..snip...
>
> <td>{{ mov.id }}</td>
>
> ...snip...
>
> works fine, but
>
> <td>{{ mov.in }}</td>

I'm guessing 'in' is a reserved token.

Guido Rumi

unread,
Feb 24, 2014, 1:59:14 PM2/24/14
to chica...@googlegroups.com
Oh!
That was it! Now I feel stupid :P
Thanks! 



Fredrik de Vibe

unread,
Feb 24, 2014, 3:48:26 PM2/24/14
to chica...@googlegroups.com
Guido Rumi <guido...@gmail.com> writes:

> Oh!
> That was it! Now I feel stupid :P

Well, I don't think it is that obvious, it should probably be possible
for the parser to circumvent this somehow.
https://github.com/erlydtl/erlydtl/issues/21 touches in on the subject,
and after Evan's patch there, the remaining reserved words are

"not", "and", "in", "or", "as", "by", and "with"

so for the time being, I guess you're somewhat out of luck. :-P

An easy workaround, however, is to define an alias for 'in' in the
model:

in_alias() ->
In.

and use this in the template instead:

mov.in_alias



- Fredrik
Reply all
Reply to author
Forward
0 new messages