私はコントローラーにこのかなり長いjson出力を持っていますが、それは良い習慣のように思われるので、モデルに移動したいと思います。まず、コントローラーメソッド:
def dashboard
@line_items = LineItem.all
respond_to do |format|
format.json { render json: @line_items.as_json(include: {project: {include: {spec: {methods: [:dashboard_due_at]} },methods:[:company_name, :contacts_names, :owner_names] }}, methods:[:dashboard_created_at, :dashboard_length])}
end
end
as_jsonからLineItemモデルにすべてを移動して、次のことができるようにするにはどうすればよいですか?
format.json { render json: @line_items.dashboard_json }
ありがとう!