ruby on rails - How to prefill ActiveAdmin form value from another model? -
in following code, how 1 populate prefilled form field value model activeadmin form:
activeadmin.register person index column :forename column :surname column :code |p| mycode.find_by_person_id(p.id).code end column :updated_at default_actions end filter :forename filter :surname form |f| f.inputs "person" f.input :forename f.input :surname # how value here, e.g. mycode.find_by_person_id(p.id).code above #f.input :code, :input_html => { :value => value??? }, as: :hidden end f.actions end end
as nistvan commented above, has_one
relationship fetches related object form object, problem solved with:
activeadmin.register person index column :forename column :surname column :code |p| mycode.find_by_person_id(p.id).code end column :updated_at default_actions end filter :forename filter :surname form |f| f.inputs "person" f.input :forename f.input :surname f.input :code, :input_html => { :value => f.object.my_code.code }, as: :hidden end f.actions end end
Comments
Post a Comment