Reputation: 28097
I have a has_many
relation for which I have disabled destroying:
unless f.object.new_record?
f.inputs do
f.has_many :foos, allow_destroy: false do |foo|
foo.input :bar
end
end
end
Currently once I've saved the main object and go back and edit, I can edit previously created foo
s. I'd like this to not be the case and only have the ability to add new ones. How can I achieve this?
I can see ActiveAdmin provides allow_destroy
and new_record
, but there isn't something analogous to allow_edit
.
Upvotes: 0
Views: 672
Reputation: 28097
Turns out the answer was staring me in the face: new_record?
. Simply check whether the has_many
item is a new record or not:
f.inputs do
f.has_many :foos, allow_destroy: false do |foo|
if foo.object.new_record?
foo.input :bar
end
end
end
Upvotes: 2