On Miércoles, 24 de Febrero de 2010 15:31:31 Benjamin Adler escribió:
> On Wednesday 24 February 2010 13:53:22 Sergio Cambra .:: entreCables S.L.
> > To use that strange association (self-referencing without foreign key) in
> > a nested scaffold you must remove that association from includes:
> > config.column[:catalog_items].includes = nil
>
> With any combination of the model containing "has_many :catalog_items" and
> the controller having a preceding line "config.columns << :catalog_items"
> that line causes an error:
>
> undefined method `column' for CatalogItemsController:Class
You don't need to add catalog_items to config.columns, it's an association and
it's added by default.
>
> > Then, you need to remove conditions added for constraints, or you only
> > will get the same record. Add this to your controller:
> >
> > def condition_from_association_constraint(association, value)
> > return nil if association.name == :catalog_items
> > super
> > end
>
> Done.
>
> > And left the beginning_of_chain method which you had before:
> > ...
>
> 1) (slightly modified to check for parent's classname):
> def beginning_of_chain
> if nested?
> parent_record = find_if_allowed(nested_parent_id, :read
> ,params[:parent_model])
> if parent_record.class.name == "CatalogItem"
> super.isotypecontrol(parent_record.conjugate, parent_record.fragment,
> parent_record.isotypeh, parent_record.origin)
> else
> super
> end
> else
> super
> end
> end
Here is simplified:
def beginning_of_chain
if nested? && params[:parent_model] == CatalogItem
parent_record = find_if_allowed(nested_parent_id, :read
,params[:parent_model])
super.isotypecontrol(parent_record.conjugate, parent_record.fragment,
parent_record.isotypeh, parent_record.origin)
else
super
end
end
>
> 2)
> def beginning_of_chain
> if action_name == 'similar'
> parent_record = find_if_allowed(params[:id], :read)
> super.isotypecontrol(parent_record.conjugate, parent_record.fragment,
> parent_record.isotypeh, parent_record.origin)
> else
> super
> end
> end
>
> What do you mean by "left the beginning"? There's now two versions of
> beginning_of_chain, 1) and 2).
>
> 1) gives a working "Similar" link, but that link produces a table
> containing all CatalogItems, not just the ones scoped by isotypecontrol.
> Might be due to the error above?
This must be used if you use an association and a nested scaffold. And don't
forget to exclude association from include option:
config.column[:catalog_items].includes = nil
>
> 2) contains the line "parent_record = find_if_allowed(params[:id], :read)",
> which leads to an infinite recursion.
This must be used if you use "similar" action link. find_if_allowed shouldn't
lead to a recursion. It's only a find and a permission check, and it can raise
an exception when record is not found or permission isn't granted.
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--
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.