Search code examples
ruby-on-railsformtastic

rails formtastic more complex associations


so I have the following models:

Country City Company CompanyOffice

The connections are like this:

Company -1:n-> CompanyOffice -> City -> Country

So now I have a formtastic form for the Company model. What works fine is changing everything in the Company model. But I want to let the user type in multiple addresses for the company.

I tried:

= semantic_form_for current_user.company, :url => url do |f|
  = f.input :name, :label => 'Company name'
  = f.input :logo, :label => 'Company Logo'
  ...

  = f.inputs :for => :company_offices do |co, i|
    = co.select :city, :collection => City.all, :label => 'City'
    = co.input :street, :label => 'Street'

This doesn't work. How would you do it?


Solution

  • do you have nested attributes in your models? see