I have a login_controller that is addressed by its URL at /login.  
Since users get confused by URLs that look like /login/login, I'd  
like the 'index' function to behave just like the 'login' function.  
(That is, I should be able to accept GET and POST actions at /login/ 
login and /login.) So I do this:

-module(login_controller).
-export([index/1,
          login/1,login/2,
          logout/1,
          signup/1]).
index(A) -> {replace,{ewc,login,login,[A]}}.
login(A) ->
   case yaws_arg:method(A) of
     'GET' ->
       {data,{[]}};
     'POST' ->
   [...]

In theory, that makes 'index' do all of the same things as 'login',  
by actually {replace}ing itself with 'login'.

This seems to work, except that the controller that calls this one  
(myapp_app_controller) actually calls it like this:

   case Ewc of
       {page,_}=Page ->
           Page;
       _ ->
           {phased, Ewc,
             fun(_Ewc, Data) ->
                 {ewc,
                  html_container,
                  [A1,
                   {ewc,
                    sidebar_container,
                    [A1,
                     {data, Data}]}]}
               end}
     end.

I do this so that I can send headers from my controller (the 'login'  
controller must send set_cookie and {ewr,...}). While this works for / 
login/login, trying it for /login or /login/index fails with:

ERROR erlang  code  crashed:
  File: appmod:0
Reason: {invalid_response,
             [{header,
                  {set_cookie,
                      ["myapp_session",61,"5", 
59,32,112,97,116,104,61,"/"]}},
              {redirect_local,[[],47,"author/show/1941"]}],
             "Response values other than 'data' and 'ewc' tuples must  
be enclosed a 'response' tuple. In addition, subcomponents may only  
return 'data' and/or 'ewc' tuples."}
Req: {http_request,'POST',{abs_path,"/login/index"},{1,1}}

This means that only the content of the {replace}d {ewc,...} has been  
replaced, not the other behaviours (such as the ability to send  
headers).

Is this a bug, or am I going about it all wrong?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to