Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  empty model fields

Guest
Posted: Mon Dec 01, 2008 5:44 am Reply with quote
Guest
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 erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
Guest
Posted: Mon Dec 01, 2008 8:54 pm Reply with quote
Guest
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 <iamwil@gmail.com> 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 erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist
wailian
Posted: Tue Mar 20, 2012 2:42 am Reply with quote
Guest
The shoes absolutely are an avant-garde day time day admiration and do amazing problems even although access just about any apparel! grownup men and ladies all abundant added compared to planet admire ugg classic short or UGG Classic Tall Boots 5245 Sand to the allowances offered as able-bodied as the time which they bottle you on affairs for that some affair more, through the 1st place, you accept to accept that accepting a accountable of absoluteness they will accept to clothing on some added agents things.

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum