lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


After the last message, I did some corrections. Sorry for the basic
errors. Actually, it's always the same at the begining. As default,
the screen reader does not read the ponctuations. If this option is
activated, the reading becomes very poluted. The correction was
"val:new" in the place of "val.new".

Let's show what is working.

The table is correctly created:

create table entries
(
id integer primary key not null,
created datetime not null,
content text not null
);

The model seems to be correct:

-- ~/models/entry.lua

local val = require('valua')
local M = {}

M.attributes = {
{id = 'safe'},
{created = val:new().not_empty()},
{content = val:new().not_empty()}
}

M.db = {
key = 'id',
table = 'entries'
}

return M

Why did I say the model is correct? Becose doing "lua
model/entry.lua", no erros are shown.

The controler seems to be correct too:

-- ~/controlers/entry.lua

local M = {}

function M.index(page)
page:render('index')
end

function M.create(page)
local entry = sailor.model('entry'):new()
local saved

if next(page.POST) then
entry.get_post(page.POST)
saved = entry.saved()
if saved then
page:redirect('entry/index')
end
end
end

return M

Doing "lua ~/controlers/entry.lua", no errors are shown.

As everything seemed OK, I have started the server and, accessing
http://localhost?8080/entry/create";, I got the following message:

./controllers/entry.lua:8: attempt to call method 'new' (a nil value)
stack traceback:
	./controllers/entry.lua:8: in function <./controllers/entry.lua:7>
	(tail call): ?
stack traceback:
	/usr/local/share/lua/5.1/coxpcall.lua:35: in function
	(tail call): ?
	(tail call): ?
	/usr/local/share/lua/5.1/sailor.lua:204: in function
	(tail call): ?
	/usr/local/share/lua/5.1/remy.lua:142: in function 'run'
	/usr/local/share/lua/5.1/sailor.lua:38: in function 'launch'
	index.lua:2: in main chunk

The line 8 is:

local entry = sailor.model('entry'):new()

I can't understand what's is wrong. when the model was tested
separately, it seemed to be correct. Whem the controler was tested
separately, it seemed to be correct. But, when the both worked in
colaboration, an error is raised.

Yes, it's clear that the problem occurs when the controler calls the
model, but the message does not help me to find the problem.

I am afraid of asking something unbelievably obvious, but I can't
really find the error.


2015-02-28 11:15 GMT-03:00, luciano de souza <luchyanus@gmail.com>:
> Hello all,
>
> I got an error about a Sailor model.
>
> Let's see the database structure:
>
> create table entries
> (
> id integer primary key not null,
> created datetime not null,
> content text not null
> );
>
> Now, let me show how I have represented it in the Sailor model:
>
> -- /models/entry.lua
>
> local val = require('valua')
> local M = {}
>
> M.attributes = {
> {id = 'safe'},
> {created = val.new().datetime()},
> {content = val.new().text()}
> }
>
> M.db = {
> key = 'id',
> table = 'entries'
> }
>
> return M
>
> I did:
> $ lua entry.lua
>
> I got:
>
> lua: /usr/local/share/lua/5.1/valua.lua:45: attempt to index local
> 'self' (a nil value)
> stack traceback:
> 	/usr/local/share/lua/5.1/valua.lua:45: in function 'new'
> 	entry.lua:6: in main chunk
> 	[C]: ?
>
>
> Accessing http://localhost:8080/entry/create, the error points to the
> same line 6, in other words:
> created = val.new().datetime()
>
> The answer is that I don't know how to represent datetime values in
> the Sailor model sintax.
>
> Before an integer, I would do:
> age = val.new().integer()
>
> Before a text, I would do:
> name = val.new().text()
>
> but what to do in the case of datetime values?
>
> In Sqlite3, I have the option to define created as a datetime or a
> timestamp, but, the doubt is the same in the both cases.
>
> Best regards,
>
> --
> Luciano de Souza
>


-- 
Luciano de Souza