【发布时间】:2015-07-17 14:32:35
【问题描述】:
考虑以下show.json.jbuilder 模板:
json.user do |json|
json.extract! @user, :id, :username, :email, :created_at, :avatar
end
json.policies do |json|
json.array!(@policies) do |policy|
json.extract! policy, :id, :title, :cached_votes_score
end
end
json.liked do |json|
json.array!(@liked) do |policy|
json.extract! policy, :id, :title, :cached_votes_score
end
end
json.disliked do |json|
json.array!(@disliked) do |policy|
json.extract! policy, :id, :title, :cached_votes_score
end
end
是否可以将它们分成四个不同的模板,然后将它们包含在show 模板中?比如:
include template_user
include template_policies
include template_liked
include template_disliked
如果这是不可能的,有什么替代方法可以创建更模块化的 jbuilder 代码?我发现我的 jbuilder 代码非常不干。
【问题讨论】:
标签: ruby-on-rails json jbuilder