How could I render to a string a JSON representation of a JBuilder view?

后端 未结 8 1537
抹茶落季
抹茶落季 2020-12-29 05:18

I\'m using JBuilder as to return some JSON. I have a index.json.jbuilder that generates the data, and I need to render it to a string. However, I\'m not sure ho

8条回答
  •  我在风中等你
    2020-12-29 05:49

    Following justingordon's tip.

    If you are using a React component, you can do the following.

    In your controller:

    @users = User.all
    

    In your view:

    <%= react_component("YourComponentName",
                        props: render('your_template.json.jbuilder')) %>
    

    This was tested on Rails 5.1.

提交回复
热议问题