在 ChicagoBoss 中的 before_ 调用之后不调用控制器操作
Controller action isn't invoked after before_ call in ChicagoBoss
我正在尝试学习 ChicagoBoss MVC 网络框架,本教程似乎是一个不错的开始
https://github.com/ChicagoBoss/ChicagoBoss/wiki/an-evening-with-chicago-boss
在作者引入 before_
函数以确保 required_login
被调用之前,这一切都是美好而令人兴奋的。我面临的问题是 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}]}
这里是 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.
这是我在访问 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.
我从 https://github.com/ChicagoBoss/ChicagoBoss 下载了 ChicagoBoss,我正在使用 Erlang 18
原来我得到通知outings_outgoer_controller:list/2 is not exported
是因为`list'函数编译失败,因为我忘了用点结束函数。无论如何,我从 http://learnyousomeerlang.com/errors-and-exceptions 那里得到了提示
./module.erl:2: function some_function/1 undefined
The function does not exist.
You've written the wrong name or arity either in the -export attribute or when declaring the function. 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.
我正在尝试学习 ChicagoBoss MVC 网络框架,本教程似乎是一个不错的开始
https://github.com/ChicagoBoss/ChicagoBoss/wiki/an-evening-with-chicago-boss
在作者引入 before_
函数以确保 required_login
被调用之前,这一切都是美好而令人兴奋的。我面临的问题是 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}]}
这里是 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.
这是我在访问 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.
我从 https://github.com/ChicagoBoss/ChicagoBoss 下载了 ChicagoBoss,我正在使用 Erlang 18
原来我得到通知outings_outgoer_controller:list/2 is not exported
是因为`list'函数编译失败,因为我忘了用点结束函数。无论如何,我从 http://learnyousomeerlang.com/errors-and-exceptions 那里得到了提示
./module.erl:2: function some_function/1 undefined The function does not exist.
You've written the wrong name or arity either in the -export attribute or when declaring the function. 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.