0

How I can make this form in activeadmin?

<%= form_for(@album, :html => {:multipart => true}) do |f| %>
.....

<div class="field">
<%= f.label :apellido %><br />
<%= f.text_field :apellido %>
</div>

<div class="field">
    <p>Hijos</p>
    <%= f.fields_for :hijos do |builder| %><br /><br />
    <%= builder.label :nombre, 'Nombre Hijo' %><br />
    <%= builder.text_field :nombre %><br />
    <%= builder.label :apodo, 'Apodo Hijo' %><br />
    <%= builder.text_field :apodo %><br />
    <%= builder.label :hijo_id, 'favorito' %>
    **<%= f.radio_button :hijo_id, builder.object.id %>**
    <% end %>
</div>

I need put the option of hijo_id inside the for of :hijos

Try with :

 f.input :avatar_item_id, :as => :boolean, :value =>  app_f.object.id 

But not work.

Thanks

2
  • What are the relationships you have set up for Album and Hijo models? Commented Nov 22, 2011 at 2:59
  • Album = Padre Album ->> nombre, apellido, hijo_id Hijo ->> nombre, apodo Commented Nov 22, 2011 at 15:09

1 Answer 1

1

This should work once you register the Album model as an ActiveAdmin resource:

  form :html => {:multipart => true} do |f|
    f.inputs "Principal" do
      f.input :apellido
    end

    f.inputs "Hijos" do
      f.has_many :hijos do |h|
        h.input :nombre
        h.input :apodo
        h.input :favorito, :as => :check_box
      end
    end
    f.buttons
    end

If you want to mark a child as a favorite, you need a boolean favorito field in the hijos table, not a hijo_id field.

Sign up to request clarification or add additional context in comments.

3 Comments

I want that father table save the favorites son (hijo) if father table has the favorites just need a query. If son table save the favorites need other query for know who is the favorites and need made more validations for not save duplicates favorites in sons tables Greetings
In that case the hijo_id must be outside the nested form, not inside. The hijo_id must be saved in the Father table
the 'favorite' field is part of the Fhater model but need collect the value of the Item Need something like this. (in front form works, but not in the admin) f.input :favorito, :value => h.object.id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.