ruby - Render fields for array attribute in Rails form object -


right im having hard time render form fields array attribute inside may form object. im using virtus gem setting attributes.

my code:

class journalform   include virtus.model    extend activemodel::naming   include activemodel::conversion   include activemodel::validations    attribute :group_no, string   attribute :description, string   attribute :rank_code, string   attribute :transaction_type, string   attribute :type, string   attribute :accounts, array[journalaccountattribute]    validates_presence_of :group_no, :description, :rank_code, :transaction_type,:type  end 

this journalaccountattribute class

class journalaccountattribute   include virtus.model    attribute :account, string   attribute :transaction_type, string end 

the problem don't know how render in view. relation 1 journal has_many accounts.

according actionview - nested attributes examples docs form in view should like:

<%= form_for @journal |journal_form| %>   ...   <% @journal.journal_accounts.each |journal_account| %>     <% if journal_account.active? %>       <%= journal_form.fields_for :journal_accounts, journal_account |journal_account_fields| %>         account: <%= journal_account_fields.text_field :account %>         transaction type: <%= journal_account_fields.text_field :transaction_type %>       <% end %>     <% end %>   <% end %>   ... <% end %> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -