Hi,
I have successfully used AS to list, update, create and delete using
nested forms, however there appears to be an issue when I attempt to
filter the values available to the user in a dropdown box.
Here are my tables:
Customers:
id
company_name
Softwares:
id
vendor_name
CustomerSoftwares:
id
software_id
customer_id
notes
CustomerSoftwareBundles:
id
customer_id
bundle_name
CustomerSoftwareBundleItems:
id
customer_software_bundle_id
customer_software_id
notes
Here are my models and associations:
Customer:
has_many :customer_software_bundle
has_many :customer_vendor
has_many :customer_software
Software:
has_many :customer_software
CustomerSoftware:
belongs_to :customer
belongs_to :software
CustomerSoftwareBundle:
has_many :customer_software_bundle_item
belongs_to :customer
CustomerSoftwareBundleItem
belongs_to :customer_software_bundle
belongs_to :customer_software
I added the following to the CustomerController to allow me to list,
create and update Customers, along with associated CustomerSoftwares,
and CustomerSoftwareBundles on 1 page:
CustomerController:
active_scaffold :customers do |config|
config.nested.add_link("Customer Software", [:customer_software])
config.nested.add_link("Customer Software Bundles",
[:customer_software_bundle])
end
So far, I can sucessfully view the Customers list and open the nested
'Customer Software Bundles' to edit, however, I want the
'CustomerSoftware' dropdown box on the 'Customer Software Bundles'
edit page to show only 'CustomerSoftware' for the related parent
Customer, so I added the following to the
CustomerSoftwareBundleItemHelper:
CustomerSoftwareBundleItemHelper:
def options_for_association_conditions(association)
if association.name == :customer_software
mycustid = controller.send(:active_scaffold_constraints)
[:customer]
['customer_softwares.customer_id = ?', mycustid]
else
super
end
end
All of this works as expected, with only CustomerSoftware items
belonging to the parent Customer showing in the dropdown box when
editing existing CustomerSoftwareBundleItems as a nested form.
However when I click the "Create Another" button to add a new
CustomerSoftwareItem, the dropdown list is empty.
It appears that the :active_scaffold_constraints works correctly when
editing existing items on the nested form, but does not pass the
correct association for the 2nd level of nested forms when 'creating
another'. I can't seem to be able to get the
'customer_software_bundle.customer_id' to the
CustomerSoftwareBundleItemHelper if the 'Create Another' button is
clicked, even though the dropdown boxes for existing
'CustomerSoftwareBundleItems' above it have the correct/associated
values for that customer_id )
All I need is to find a way to have the CustomerSoftware dropdown show
only the associated items for the parent Customer or
CustomerSoftwareBundle being edited, when I create another...
Any Ideas?
Cheers
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---