Can you double check that the 'friends' module has all the functions
('first_name', 'last_name', and 'picture')? Otherwise the code looks
good I think.

Btw, you should consider instead of passing the 'Friend' object to the
view to pass a function instead that lets the view indirectly access
the Friend object's field. E.g. instead of returning from the
controller function

{data, Friend}

return

{data, fun(Field) -> erlydb_base:field_to_iolist(Friend:Field()) end}

(field_to_iolist() knows how to convert erlydb field values to iolists).

Then, in the view, you can have snippets such as

<%@ show(Friend) %>name: <% Friend(name) %>

which is nicer I think than the original style.


Yariv

On Sun, Nov 30, 2008 at 9:44 PM, Wilhelm <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> Just getting started with erlyweb.  I'm currently using the same form
> in my views for both new and edit:
>
> <%@ new(Friend) %>
> <h2>Create Friend</h2>
> <b><% friends:value(friends:first_name(Friend)) %></b><br/>
> <form method="post" action="/friends/create">
>  <input type="submit" value="Create" />
> </form>
> <% a([".."], "Back") %>
>
> <%@ edit({Friend}) %>
> <h2>Edit Friend</h2>
> <form method="post" action="/friends/edit">
>   <% friend_form(Friend) %>
>   <input type="submit" value="Edit" />
>  </form>
> <% a([".."], "Back") %>
>
> <%@ friend_form(Friend) %>
>  <table>
>    <% friend_field(Friend, first_name) %>
>    <% friend_field(Friend, last_name) %>
>    <% friend_field(Friend, picture) %>
>  </table>
>
> <%@ friend_field(Friend, FieldName) %>
>  <tr>
>    <td>
>      <input type="text"
>             name="<% atom_to_list(FieldName) %>"
>             value="<% friends:FieldName(Friend) %>" />
>    </td>
>  </tr>
>
> This doesn't work for the new page since the FieldName for a Friend is
> empty.  What do I do so that I can use the same form code for both new
> and edit, so that it doesn't crash the code?
>
> I've tried using this function instead of calling friends:FieldName
> (Friend) directly:
>
> value(Val) ->
>    case Val of
>        undefined ->
>            "";
>        _ ->
>            Val
>    end.
>
> But it craps out with:
> ERROR erlang  code  crashed:
>  File: appmod:0
> Reason: {badarg,[{erlydb_base,get,2},
>                 {erlyweb,'-render_response_body/7-fun-0-',6},
>                 {erlyweb,'-render_response_body/7-fun-1-',3},
>                 {lists,map,2},
>                 {erlyweb,render_response_body,7},
>                 {erlyweb,handle_request,6},
>                 {yaws_server,deliver_dyn_part,8},
>                 {yaws_server,aloop,3}]}
> Req: {http_request,'GET',{abs_path,"/myapp/friends/new"},{1,1}}
>
> What am I doing 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