JBuilder partial implied underscore
With the current function of jBuilder, you have to name a file _file.json.jbuilder to use json.partial! 'file/file'
Is there a way to remove the implied underscore in the current implementation?
If not: What would it take for this to be added? I can lend some assistance to it within a week.
If so: Can we add something to the readme to make these options more easily accessible?
Why the ask? Say you want to just render the show action template in a collection like an index or in another jBuilder altogether. Making a _show file feels like a bit of a hackaround.
That would go against the Rails convention for naming partials and views.
In a case like this, when you want to render for example a Post, the Rails way would be as follows: create a _post.json.jbuilder partial that you render from your show method using render @post and from your index method just as you're currently doing in your index.json.jbuilder. This way you don't need a show.json.jbuilder :).
@vindia Rails has render template: 'template_name'. Is there something similar in jbuilder?
@printercu I don't think so. Why would you want to use that?
I had a case when items in collection for index action were same as for show. So I had to create '_show' template and have show just with json.partial! 'show' (3 templates total, 1 extra call). With suggested approach I would have only 2 templates.
I'm glad I'm not alone here; but that making me to think again, i guess that one step isn't that a big deal in comparison to go against conventions & the need of more API to cover these marginal situations..