legacy-docs icon indicating copy to clipboard operation
legacy-docs copied to clipboard

Missing rendering Views from Controller documentation

Open alanondra opened this issue 4 years ago • 4 comments

I had to go to Form Submissions / Reading Form Data to see how to render Views from Controllers. It should probably be included in both View and Controller documentation.

alanondra avatar Aug 15 '20 20:08 alanondra

Shouldn't you simply check views docs to see how to render views? https://preview.adonisjs.com/guides/views/introduction#usage

thetutlage avatar Aug 16 '20 04:08 thetutlage

Can you highlight the part where it says view needs to be imported from HttpContextContract in the Controller method signature? Perhaps where HttpContextContract needs to be imported from?

alanondra avatar Aug 16 '20 12:08 alanondra

Well, not sure what exactly you are upto.

Copy/paste the following code in routes file and it will work without any modifications

20200816_180253.jpg

When you create a new controller using node ace make:controller command. It does import the HttpContextContract for you.

So just like the route callback, you use the view inside a controller. Not sure if that needs to be told explicitly.

Docs have to balance over writing too

thetutlage avatar Aug 16 '20 12:08 thetutlage

There is no indication on the page that you have to create this signature to use it with Controllers, merely passing { view } throws an exception:

public async index({ view } : HttpContextContract)

I'm telling you as a user that the documentation was not clear and there was no way to intuit that this was necessary, otherwise this ticket wouldn't have been created.

alanondra avatar Aug 16 '20 15:08 alanondra