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.
What makes Rails shine is its laser focus on speed and simplicity. It seamlessly integrates into the Rails ecosystem while cutting through the clutter of traditional rendering methods. Instead of fighting with bloated serializers Sprunki or hand-coded views, Rails allows developers to craft clean, declarative templates that get straight to the point. It's opinionated where it counts, and flexible when you need it to be.