I have 2 activeadmin resources, both are subclasses of a model, using STI. For example:
base_model.rb
class BaseModel < ActiveRecord::Base
end
male_model.rb
class MaleModel < BaseModel
end
female_model.rb
class FemaleModel < BaseModel
end
admin/male_model.rb
ActiveAdmin.register MaleModel do
menu :parent => "Models", :label => "Male Model"
# A big long custom form follows...
form do |f|
f.inputs
f.buttons
end
end
admin/female_model.rb
ActiveAdmin.register FemaleModel do
menu :parent => "Models", :label => "Female Model"
# The SAME big long custom form follows...
form do |f|
f.inputs
f.buttons
end
end
What would be the correct way to render the same form, but create a record of a different subclass, either MaleModel or FemaleModel?
What I’m doing now is maintaining 2 activeadmin resources with almost exactly the same (bulky) code within. Totally unDRY. Please share what you’ve done in this situation.
John
I haven’t try this but you could define an
@objectvariable in the controller:And then you could render a form and use the variable
@objectinstead of@male_modelor@female_model.