GenieFramework / Genie.jl

🧞The highly productive Julia web framework
https://genieframework.com
MIT License
2.25k stars 190 forks source link

Issues with the controller example from the docs #697

Open MariusDrulea opened 8 months ago

MariusDrulea commented 8 months ago

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:MessageControllernot defined

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

MariusDrulea commented 8 months ago

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

essenciary commented 8 months ago

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

PGimenez commented 8 months ago

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

MariusDrulea commented 8 months ago

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.