Question

I follow the REST API with yaws tutorial of the 'Building web application with Erlang' book.

I get the following error when starting $ yaws :

file:path_eval([".","/Users/<uername>"],".erlang"): error on line 3: 3: evaluation failed with reason error:{undefined_record,airport} and stacktrace [{erl_eval,exprs,2,[]}]

.erlang file:

application:start(mnesia).
mnesia:create_table(airport,[{attributes, record_info(fields, airport)}, {index, [country]}]).

rest.erl file can be found here.

How can I define a record? I tried to add rd(airport, {code, city, country, name}). without success.

Was it helpful?

Solution

Record 'airport' is defined in the module rest, and all functions in the 'rest' know about record 'airport'. But when you start your application, erlang executes .erlang file, which has nothing to do with the module rest. So, erlang just has no idea what is the record airport and where to find it.

Easiest workaround I believe - is to define some function (for instance 'init') in the module rest, this function must contain all that you have now in .erlang file, export it, and in the .erlang file just invoke rest:init().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top