I am having this rather long json output in my controller, I wish to move it into the model as it seems to be a good practice. First off, the controller method:
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
How can I move everything starting from as_json into the LineItem model so that I can just do
format.json { render json: @line_items.dashboard_json }
Thank You!
in your LineItem model