1

I am trying to make a form for storing data hierarchy through the associations.

My structure of database is

meta
 - ID (PK)
version
 - meta_id (FK of meta)
 - ID (PK)
 - lang (FK from lang ...)
 - ....
data
 - ID (FK of version)

I need to store multiple language content under one ID.

Models are

class Meta < Sequel::Model(:link_meta)

  one_to_many :version 

end

class Version < Sequel::Model(:link_version)

  one_to_one :meta, key: :meta_id
  one_to_many :data, key: :id
  one_to_one :lang, key: :lang

end

class Link < Sequel::Model(:link)
  plugin :timestamps, :create => :created, :update => :updated

  many_to_one :version, key: :id

end

And my form for creating input is.

  <% form_for :links, url(:links, :create), :class => 'form-horizontal' do |f| %>
    <%= partial 'links/form', :locals => { :f => f } %>
 <% end %>

And this is my partial

<% f.fields_for :version, :class => 'form-horizontal' do |cz| %>
  <%= cz.hidden_field :lang, :value => Lang.select(:id).where(:lang => "cz").map(:id) %>

  <% cz.fields_for :data, :class => 'form-horizontal' do |link| %>

    <% error = @links.errors.key?(:url) && @links.errors[:url].count > 0 %>
    <fieldset class='control-group <%= error ? 'has-error' : ''%>'>
     ... form content
    </fieldset>
  <% end %>

  <% f.fields_for :version, :class => 'form-horizontal' do |en| %>
  <%= en.hidden_field :lang, :value => Lang.select(:id).where(:lang => "cz").map(:id) %>

    <% en.fields_for :data, :class => 'form-horizontal' do |link| %>

      <% error = @links.errors.key?(:url) && @links.errors[:url].count > 0 %>
      <fieldset class='control-group <%= error ? 'has-error' : ''%>'>
      ... another form content
     </fieldset>
  <% end %>
<% end %>

But it fails on

undefined method `data' for [:class, "form-horizontal"]:Array

I tried different association combinations etc, I feel lost.

Thanks

Levi

Levi
  • 77
  • 7
  • from the error-message, it looks a bit like you are missing a comma or doing some typo so that `:class => 'form-horizontal'` is passed as a the form-object somewhere – phoet Mar 05 '18 at 20:14
  • I am using same way that in the other forms without nested (inlayed) forms. I saw here [https://stackoverflow.com/questions/24746906/ruby-on-rails-saving-in-two-tables-from-one-form] that this kind of error means bad association. When I simply try to find the :data with binding, it fails too. And above with version is working properly. – Levi Mar 06 '18 at 05:32

0 Answers0