json[:comments] = {
content: @message.comments.content,
created_at: @message.comments.created_at
}
这样的写法会变成:
"comments": [
{ "content": "Hello, world!", "created_at": "2016-06-29T20:45:28-05:00" },
{ "content": "<script>alert('Hello, world!');</script>", "created_at": "2016-06-29T20:47:28-05:00" }
]
这样真的好么。。。还嫌 Rails 中隐藏起来的知识不够多么。。。
JBuilder is a popular gem for Ruby on Rails that serves as a powerful JSON API template engine. It allows you to create flexible Fireboy and Watergirl Game and readable JSON structures with ease. Below is a guide on how to set up and use JBuilder in your Rails application.