Are accept fields in an update action required by default?
I have the following update action:
I would expect that in this case the
status
is a optional field and will be nil if I don't send it as an action argument.
But if I do that, I actually get the following error:
An I missing something of this is the expected behavior?4 Replies
Shouldn't be. Perhaps
set_when_nil?
is not doing what you expect?
Separately, arg(;status)
has no effect if there is no status argument
if you do accept
you don't need to add arguments
but in your case it seems like you want to not set it if its nil so I'd do:
Seems like a strange pattern. Wouldn't they just leave out the status if they don't want to change it?You mean that the update can be like this?
update :update_images do
accept [:id, :status, :images]
end
Since
status
and images
are fields inside the resource?Yes,
accept
means "these attributes are writable"
By default the accept list is all public writable attributes, but that will change in the next major versionMakes sense, and it worked 😄