ruby on rails - activeadmin edit prefill fields? -


in active admin belong_to/foreign key object fields being showed as drop down. requirement was, user should capable give input if input new create new entry of foreign key while creating entry. suppose have 2 table person , car, every person has 1 car.

so added parameter car_name_str following way:

form |f|     inputs       input :name       input :address       input :car_string     end end 

i added controller can take car_string , create new car. problem is, when try edit, car_string remains empty. how can prefil it?

have read nested resources in activeadmin?

what can override new action initialise new car:

controller   def new     @user = user.new     @user.cars.build(name: 'my awesome car')   end end 

then, in form can write this:

form |f|   inputs     input :name     input :address      f.has_many :cars, heading: nil, allow_destroy: false, new_record: false |a|       a.input :name     end   end end 

this way form initialised new car and, when you'll want edit user, you'll appropriate values car.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -