Genie.jl icon indicating copy to clipboard operation
Genie.jl copied to clipboard

Issues with the controller example from the docs

Open MariusDrulea opened this issue 1 year ago • 4 comments

I'm having problems with the autoload of controllers, usage in the docs https://learn.genieframework.com/docs/guides/adding-dynamic-pages#pages-with-a-controller. So what am I doing wrong here?

system: Linux and Julia 1.10

image

The error: ERROR: UndefVarError: MessageController not defined

If I include the file directly, as in the commented code, everything works as expected.

MariusDrulea avatar Jan 07 '24 11:01 MariusDrulea

I tested with Julia 1.9.4 and downgraded to Genie v5.21.2 and GenieFramework v1.26.4 and still does not work.

MariusDrulea avatar Jan 08 '24 10:01 MariusDrulea

@MariusDrulea can you maybe share the whole app (on Github) so we can take a look at and try it out?

essenciary avatar Jan 08 '24 12:01 essenciary

Apparently the context parameter is missing, the module loads after adding it: Genie.Loader.autoload("controllers", context=Main.App)

However, there's another error in the controller code after that which I don't recall seeing before...

That guide was a quick way to introduce the MVC architecture, but now I'm seeing that perhaps it was not a good idea. I'll remove it from the docs.

If you want to use controllers or adopt MVC, I suggest you use Genie.Generator.newapp to create your app and build from there. We have two good long tutorials on this:

Books app

Movies app

PGimenez avatar Jan 08 '24 12:01 PGimenez

hm... It works if you directly include the MessageController.jl file. If I have a lot of controllers and models and views, I would probably want to include each controller individually for the specific model and view. Not all at once. Not sure if this is relevant.

Going to try the .newapp functionality. Played a bit with the GenieBuilder, it's very cool.

MariusDrulea avatar Jan 08 '24 21:01 MariusDrulea