Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering partials inline requires #to_json #32

Open
pyrareae opened this issue Feb 4, 2020 · 3 comments
Open

Rendering partials inline requires #to_json #32

pyrareae opened this issue Feb 4, 2020 · 3 comments

Comments

@pyrareae
Copy link

pyrareae commented Feb 4, 2020

When calling rendering a partial a different template format, such as slim in my case, the render call needs to have #to_json called on it otherwise it returns a ruby hash instead of valid json. I didn't see any heads ups on this in the documentation so I'm not sure if this is intentional behavior or not.

For example, using jbuilder you can use something like this:

render partial: 'entry', object: @entry, formats: :json

whereas with jb you need this:

render(partial: 'entry', object: @entry, formats: :json).to_json
@sebyx07
Copy link
Contributor

sebyx07 commented Apr 14, 2021

It is correct, because a .jb file returns a hash

@nathandrew
Copy link

I ran into this today – maybe at a minimum update the readme if it is intended to work that way.

@nathandrew
Copy link

In my case I was just looking to render a partial inside of an object:

{
  spotlight: render(partial: 'spotlight', locals: { spotlight: @spotlight })
}

That worked for me 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants