[英]Controller action isn't invoked after before_ call in ChicagoBoss
I am trying to learn ChicagoBoss MVC web framework and this tutorial seemed a good start 我正在尝试学习ChicagoBoss MVC Web框架,本教程似乎是一个好的开始
https://github.com/ChicagoBoss/ChicagoBoss/wiki/an-evening-with-chicago-boss https://github.com/ChicagoBoss/ChicagoBoss/wiki/an-evening-with-chicago-boss
It was all great and exciting untill the author introduced the before_
function to ensure that required_login
is invoked. 这一切都很棒且令人兴奋,直到作者介绍了before_
函数以确保调用required_login
。 The problem I am facing is that the list
function stopped being called, here is my code 我面临的问题是list
函数停止被调用,这是我的代码
-module(outings_outgoer_controller, [Req]).
-compile(export_all).
% -export([list/3]).
before_ (Action) ->
io:fwrite("in before_ Action is: ~s~n", [Action]),
case Action of
"login" ->
ok;
"register" ->
ok;
_ ->
io:fwrite(" - login is required for this action!~n", []), %gets printed successfully
Outgoer = user_lib:require_login(Req),
io:fwrite(" - ~p is logged in~n", [Outgoer]), %gets printed successfully
Outgoer
end.
list('GET', [], Outgoer) ->
io:fwrite("An outgoer is requesting his list~n", []), % never gets printed
{ok, [{outgoer, Outgoer}]}
and here is the require_login
function 这是require_login
函数
require_login(Req) ->
case Req:cookie("user_id") of
undefined -> {redirect, "/outgoer/login"};
Id ->
case boss_db:find(Id) of
undefined -> {redirect, "/outgoer/login"};
Outgoer ->
case Outgoer:session_identifier() =:= Req:cookie("session_id") of
false -> {redirect, "/outgoer/login"};
true -> {ok, Outgoer}
end
end
end.
and this is the prints i get in my console while accessing outgoer/list
这是我在访问outgoer/list
在我的控制台中获得的打印件
in before_ Action is: list
- login is required for this action!
- {ok,{outgoer,"outgoer-1","mohamed","1@3.com",
"a982ff46c5664edc593329ab558445fc"}} is logged in
20:29:31.439 [notice] [ChicagoBoss] The function outings_outgoer_controller:list/2 is not exported, if in doubt add -export([list/2])) to the module
20:29:31.440 [info] GET /outgoer/list [outings] 200 18ms
Reloading outings_outgoer_controller ... fail: nofile.
I downloaded ChicagoBoss from https://github.com/ChicagoBoss/ChicagoBoss and I am working with Erlang 18
我从https://github.com/ChicagoBoss/ChicagoBoss下载了ChicagoBoss,我正在使用Erlang 18
It turns out that I got the notice outings_outgoer_controller:list/2 is not exported
because the `list' function failed to compile because I forgot to end the function with a dot. 事实证明我得到通知outings_outgoer_controller:list/2 is not exported
因为`list'函数无法编译,因为我忘了用点结束函数。 anyway I got that hint from http://learnyousomeerlang.com/errors-and-exceptions it says 无论如何,我从http://learnyousomeerlang.com/errors-and-exceptions得到了这个暗示
./module.erl:2: function some_function/1 undefined The function does not exist. ./module.erl:2:function some_function / 1 undefined该函数不存在。
You've written the wrong name or arity either in the -export attribute or when declaring the function. 您在-export属性中或在声明函数时写了错误的名称或arity。 This error is also output when the given function could not be compiled, usually because of a syntax error like forgetting to end a function with a period. 当无法编译给定函数时,也会输出此错误,通常是因为忘记结束具有句点的函数等语法错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.