I did the following to get Acts as Versioned working:

In application.rb
def self.active_scaffold_controller_for(klass)
  # return the correct controller for the versions
  begin
    if klass.to_s =~ /^.*::Version$/
      return klass.to_s.gsub(/::Version
$/,'VersionController').constantize
    else
      super(klass)
    end
  rescue => exception
    super(klass)
  end
end

In my DeviceController:
config.nested.add_link("History", [:versions])

Then I have a device_version_controller.rb:
class DeviceVersionController < ApplicationController
  active_scaffold "device/version" do |config|
  end
end

You can also do some fancy diff highlighting by updating the
column_class method in the AS lib/helpers/view_helpers.rb.  My code
for this is out of date, so I'll leave this up to you to figure out.

Tys


On Feb 2, 9:43 am, "Sergio Cambra .:: entreCables - Symbol Servicios
Informáticos S.L. ::." <[email protected]> wrote:
> El Monday 02 February 2009 15:37:19 Andreas Eckert escribió:
>
> > With the new code I get the following error:
>
> >    undefined method `original_class' for #<Class:0x24ddfe4>
>
> > I got acts_as_versioned 0.2.3 installed.
>
> Run script/console and try
> Original.versioned_class_name
> Original.versioned_class_name.constantize.original_class
>
> Replace Original with the model where you has acts_as_versioned
>
>
>
>
>
> > On Feb 2, 2009, at 9:50 PM, Sergio Cambra .:: entreCables - Symbol
>
> > Servicios Informáticos S.L. ::. wrote:
> > > El Thursday 29 January 2009 14:35:28 Andreas Eckert escribió:
> > >> 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.
>
> > > Some improvements:
> > > - eval is slow, it's better to use send. Also you can get a class
> > > from a string using constantize.
> > > - You can get source model from versioned class with original_class
> > > - Use values method instead of keys method to get the first key of a
> > > hash to get the first value
> > > - You can get the model class with
> > > self.controller_name.singularize.camelize, or better, with
> > > self.active_scaffold_config.model
>
> > > def conditions_for_collection
> > >   # we need to remove the text "version" from the end of the
> > > controller name to get the originating controller
> > >   source_model = active_scaffold_config.model.original_class
> > >   record = source_model.find_by_id,
> > > active_scaffold_constraints.values[0]
> > >   ["#{active_scaffold_config.model.table_name}.version != ?",
> > > record.version] unless record.nil?
> > > end
>
> > >> 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]
>
> > > --
> > > 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