On Wednesday 24 February 2010 13:53:22 Sergio Cambra .:: entreCables S.L. ::. 
wrote:
> Try the following statement in script/console:
> CatalogItem.first.isotests
> Does it work? If it work, association is right, then we only have to fix
> showing that association in a nested scaffold.

Yes, it returns all CatalogItems meeting the criteria.

> If you use default routes, you don't need to add anything to your routes.rb
> and you will get an URL like catalog_items/similar/:id

I use default routes and thats the URL I get 
(https://.../catalog_items/similar/3?_method=get)

> 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

> 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

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?

2) contains the line "parent_record = find_if_allowed(params[:id], :read)", 
which leads to an infinite recursion.

ben

-- 
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.

Reply via email to