[erlang-questions] erlyweb accessing record fields

jm jeffm@REDACTED
Mon Jul 2 14:31:39 CEST 2007


In writing a view for a component which displays one entry, call it mod,
with a field called name I am attempting to access the values with

mod:name(Data)

which I thought would work based on the metafunctions, but this causes
an error where Data is a list of tuple. I can get it to work with

element(4,lists:nth(1,Data))

which is not very practical and from what I read else where
mod:name(Data) should work. The applicable code folllows. Any help would
be welcome even pointing out the obvious :-).

In mod_controller.erl
-export([show/3]).

show(A, Model, Id) ->
    Rec = Model:find_id(Id),
    Fields = tl(Model:db_fields()),
    Vals = tl(Model:to_iolist(Rec)),
    FV = lists:zip(Fields, Vals),
    %%    IdStr = case Model:id(Rec) of
    %%         undefined -> [];
    %%         Id -> integer_to_list(Id)
    %%     end,
    FieldData = [{erlydb_field:name_bin(Field),
                  erlydb_field:html_input_type(Field),
                  erlydb_field:modifier(Field),
                  Val} || {Field, Val} <- FV],
    {data, {erlyweb:get_app_root(A),
            atom_to_list(Model),
            Id,
            yaws_arg:server_path(A),
            FieldData}}.


In mod_view.erl

-export([show/1]).

show(Data) ->
    classes_show:show(Data).

In mod_show.et, a some what cut down extract,

<%! Shows a summary %>
<%@ show({AppRoot, Model, Id, Action, Data} = Fields) %>
<table class="maintext-p" width="100%">
<tr><td colspan="3" align="center" class="maintext-h1"><%
element(4,lists:nth(1,Data)) %></td></tr>                 <--problem
<tr><td>Name:</td><td>A Name</td>
<td rowspan="2" align="center"><img src="/images/logo.jpg"></td></tr>
<%! rest of table goes here %>
</table>

----- End Extracts -----

Jeff.



More information about the erlang-questions mailing list