Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Templates when Rendering from Resource #204

Closed
paganotoni opened this issue Jan 31, 2017 · 6 comments
Closed

Templates when Rendering from Resource #204

paganotoni opened this issue Jan 31, 2017 · 6 comments
Labels
documentation Improvements or additions to documentation

Comments

@paganotoni
Copy link
Member

I noticed that when generating a resource and rendering html on it buffalo doesn't apply the shared template (application.html by default), but if you generate an action and render html buffalo seems to render the template correctly, is this happening to someone else ?

cc @bscott @markbates

@stanislas-m
Copy link
Member

stanislas-m commented Jan 31, 2017

If you look at the doc (http://gobuffalo.io/docs/generators), the resource generator does the job. It generates actions with a simple string output.

I think a resource is something intended to be served as JSON or XML, and is kinda API-oriented. Maybe some documentation improvements can be done here, since the docs does not explain its purpose clearly (http://gobuffalo.io/docs/routing says CRUD, but it's vague).

@stanislas-m stanislas-m added the documentation Improvements or additions to documentation label Jan 31, 2017
@paganotoni
Copy link
Member Author

I understand the point of resources being used for API-oriented components of the web application, or even to construct API only applications, in that context i agree that the resources are very appropriate and match exactly REST CRUD structure.

by this time we don't have JSON templates but would this imply that when using resources we wont be able to have a default template for our response and have the resource function simply fill the template data ?

Other than that what i'm trying to say (and sorry not to provide steps initially) is that HTML/JSON/XML are simply representational formats and IMHO our HTML/JSON/XML renderers should behave the same (or at least close) when being called from inside an action than inside a Resource function.

just in case i get it wrong, is what you're saying that template skipping is done by propose on resources ?

@stanislas-m
Copy link
Member

Well, it's only my understanding, so I do think it's done on purpose (and the docs displays the result according to this hypothesis).

Other than that what i'm trying to say (and sorry not to provide steps initially) is that HTML/JSON/XML are simply representational formats and IMHO our HTML/JSON/XML renderers should behave the same (or at least close) when being called from inside an action than inside a Resource function.

Sure. I guess you're right, and this example (https://github.com/gobuffalo/buffalo/tree/master/examples/html-resource) shows it can be used to display HTML pages.

By looking at the code (https://github.com/gobuffalo/buffalo/blob/master/resource.go), a resource is just a layout to provide default actions. Maybe we can add an option to the resource generator to choose a default template (XML, JSON or HTML)?

@paganotoni
Copy link
Member Author

right @stanislas-m seems its not on propose, i still owe some sample code that shows when this is happening.

@paganotoni
Copy link
Member Author

oh boy! i may have been doing something wrong on the beginning :( sorry everybody to steal some time and attention, specially @stanislas-m and @bscott, now that i'm retrying it its working correctly, i may have started with the sample code :D, so sorry about the distraction.

@stanislas-m
Copy link
Member

No problem. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants