Here to share my solution:

Got it working without hardcoding of any controller/model names, hence  
should be easily deployable to any other controller

I have put the following into my Contractversion controller:

   def conditions_for_collection
     # we need to remove the text "version" from the end of the  
controller name to get the originating controller
     source_controller =  
self.controller_name.camelize[0..self.controller_name.length-8]
     c = eval(source_controller.to_s 
+ 
".find_by_id 
(active_scaffold_constraints[active_scaffold_constraints.keys[0]])")
     # Could also use params[:controller].camelize to get the  
controller name, but I am not sure whether that covers all cases
     return [eval(self.controller_name.camelize.to_s 
+".table_name").to_s+".version  <> ?", c.version] unless c.nil?
     return ""
   end

I am not sure whether this is the most elegant way, recommendations of  
simplifying this are most welcome.

On Jan 29, 2009, at 12:01 AM, Sergio Cambra .:: entreCables - Symbol  
Servicios Informáticos S.L. ::. wrote:

>
> El Wednesday 28 January 2009 14:53:28 Andreas Eckert escribió:
>> Thanks, works like expected. I added
>>
>>   def conditions_for_collection
>>     ['contract_versions.version  <> ?', 1]
>>   end
>
> Try with active_scaffold_constraints[:version]
> If it doesn't work, try to dump active_scaffold_constraints to log  
> and look at
> the key to use:
> logger.debug active_scaffold_constraints.inspect
>
>>
>> to the controller of the versioned model (Contractversion)
>>
>> Obviously I need to replace '1' with the current version number  
>> stored
>> in the Contract record.
>> Being new at Rails, how does the Contractversion controller know  
>> which
>> Contract clicked on the "Version" link, i.e. how do I get the ID of
>> the parent (the caller) ?
>>
>> Thanks
>> Andreas
>>
>>
>>
>> On Jan 27, 2009, at 6:05 PM, Sergio Cambra .:: entreCables - Symbol
>>
>> Servicios Informáticos S.L. ::. wrote:
>>> El Monday 26 January 2009 13:49:11 Kumala escribió:
>>>> I am using activescaffold and acts_as_versioned.
>>>> I have 2 models: contract and contractversion. I have added a
>>>> "Versions" link to my scaffold using:
>>>>   config.nested.add_link("Versions", [:contractversions])
>>>>
>>>> Unfortunately, when clicking on the "Versions" link in the contract
>>>> model, it shows all contract versions, including the current  
>>>> contract
>>>> values.
>>>>
>>>> How can I prevent the latest version from being shown?
>>>
>>> You can put conditions for the find method defining a
>>> conditions_for_collection method.
>>>
>>> --
>>> Sergio Cambra .:: entreCables S.L. ::.
>>> Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
>>> T) 902 021 404 F) 976 52 98 07 E) [email protected]
>>
>>
>
>
> -- 
> Sergio Cambra .:: entreCables S.L. ::.
> Nicolás Guillén 6, locales 2 y 3. 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
-~----------~----~----~----~------~----~------~--~---

  • Ac... Kumala
    • ... Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
      • ... Andreas Eckert
        • ... Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
          • ... Andreas Eckert
            • ... Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
              • ... Andreas Eckert
                • ... Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
                • ... Tys von Gaza

Reply via email to