2016-07-30 91 views
1

我努力學習ChicagoBoss MVC Web框架before_呼叫後調用和本教程似乎是一個良好的開端控制器動作不ChicagoBoss

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","[email protected]", 
      "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工作

回答

0

事實證明,我得到了通知outings_outgoer_controller:list/2 is not exported,因爲`list'函數編譯失敗,因爲我忘了用點結束函數。反正我得到的提示從http://learnyousomeerlang.com/errors-and-exceptions它說

./module.erl:2:功能some_function/1未定義 功能不存在。
您在-export屬性中或聲明函數時寫了錯誤的名稱或參數。當給定函數無法編譯時,也會輸出此錯誤,通常是因爲語法錯誤,例如忘記用句號結束​​函數。