Rather detail my own record set, which is simple but has a lot of fields and sub-records, I'd just like to be able to get the example given on github to work, i.e. https://github.com/activescaffold/active_scaffold/wiki/API%3A-Nested
# app/models/company.rb
class Company < ActiveRecord::Base
has_many :contacts
end
# app/models/contact.rb
class Contact < ActiveRecord::Base
belongs_to :company
end
# app/controllers/contacts_controller.rb
class ContactsController < ApplicationController
active_scaffold :contacts do | config |
end
end
# app/controllers/companies_controller.rb
class CompaniesController < ApplicationController
active_scaffold :companies do |config|
config.nested.add_link("Company's contacts", [:contacts])
end
end
Obviously the contacts table has a column for company_id (i.e. foreign key).
'As is', it appears that in the companies controller, the 'companies' needs to be 'company'. So after that change, the config.nested... line causes the following error:-
Routing Error undefined method `add_link' for nil:NilClass
After trying (and failing) to fix this I just commented it out and it works quite well, however I need a one to one (or none) relationship, so made the change (contacts had to change to contact, Rails objects otherwise) :-
# app/models/company.rb
class Company < ActiveRecord::Base
has_one:contact
end
It appears to work but when a contact is updated, it makes a mess of the form, displaying the updated contact at the top of the form, just under the field labels that actually belong to the records below, i.e. the company records. It also allows more than one contact to be created when a company record is created, but this may be constrained by another method, or possibly fixed if the config.nested.add_link works.