Answer the question
In order to leave comments, you need to log in
Best way to generate errors for Rails, nested_attributes in json?
There is a model that takes attributes for a nested model, the result of the form is returned as json, and then it is drawn
class Order < ActiveRecord::Base
accepts_nested_attributes_for :entries
end
class Entry < ActiveRecord::Base
accepts_nested_attributes_for :members, allow_destroy: true
end
<input autocomplete="off" class="string required form-control" id="order_entries_attributes_1459329286687_members_attributes_1459329286739_title" name="order[entries_attributes][1459329286687][members_attributes][1459329286739][title]" placeholder="Наименование" type="text">
class OrdersController
def update
if @order.update(order_params)
render json: @order
else
render json: @order.errors, status: :unprocessable_entity
end
end
end
{"entries.members.client_id":["введите значение"],"entries.members.clinic_id":["введите значение"]}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question