Hi,

You cannot assign a named_scope to a nested.add_link configuration.

However, you can go to your car controller.
- Implement named_scopes_for_collection method.
- Detect if you controller is in nested_mode: nested?
- get your parent_record: parent_record =
find_if_allowed(nested_parent_id, :read, params[:parent_model])
- Assign your named_scope

def named_scopes_for_collection
  if nested?
     parent_record = find_if_allowed(nested_parent_id, :read,
params[:parent_model])
     [:sparepartsources, parent_record.color,
parent_record.manufacturer]
  end
end

You can further improve... For example you can check if your
parent_model is an instance of your exptected model,....

--
Volker




On 19 Feb., 21:02, Benjamin Adler <[email protected]> wrote:
> Hello!
>
> I read about named_scopes_for_collection 
> onhttp://wiki.github.com/activescaffold/active_scaffold/api-listand have a few
> questions:
>
> Given a model "Car" with attributes like color (string) and manufacturer
> (reference), I'd like to have a nested scaffold for Cars named e.g. "potential
> sparepart sources" showing only other cars with the same color and same
> manufacturer and filtering out the rest.
>
> How can I dynamically add values of the current record/row to
> CarsController::named_scopes_for_collection and what would the nested link to
> that scope have to look like?
>
> Athttp://groups.google.com/group/activescaffold/browse_thread/thread/56...
> someone suggests adding a :scope parameter to config.nested.add_link, would
> that be the way to go?
>
> I tried something similar to the following, but couldn't get any of it to
> work. Even if it did, I doubt I could just pass the color and manufacturer
> parameters from the config.nested.add_link...
>
> named_scope :sparepartsources, lambda { |*args|
>   color = args[0]
>   manufacturer = args[1]
>   :conditions => ['color = :color AND manufacturer >= :manufacturer',
>                   :color => color, :manufacturer => manufacturer]
>
> }
>
> I'm confused, could you help me get on the right track, please?
>
> thank you very much!
> 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