Forum: Ruby on Rails version_fu in Rails 2.1.1

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
tansaku (Guest)
on 2008-10-21 23:49
(Received via mailing list)
Hi,

So I read about how acts_as_versioned doesn't play so well with the
latest Rails version.

I got hold of an alternative, version_fu, but I am still having
trouble. http://github.com/jmckible/version_fu


I'm getting the following error when trying to save the versioned
model:

>> type = StatisticType.find(1)
>> type.name = 'bob'
=> "bob"
>> type.save
NoMethodError: undefined method `version=' for
#<StatisticType::Version:0x244c3a0>
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/attribute_methods.rb:251:in `method_missing'
  from /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting/
vendor/plugins/version_fu/lib/version_fu.rb:101:in
`instatiate_revision'
  from /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting/
vendor/plugins/version_fu/lib/version_fu.rb:85:in
`check_for_new_version'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:173:in `send'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:173:in `evaluate_method'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:161:in `call'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:93:in `run'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:92:in `each'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:92:in `send'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:92:in `run'
  from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/
active_support/callbacks.rb:272:in `run_callbacks'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/callbacks.rb:298:in `callback'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/callbacks.rb:206:in `create_or_update'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/base.rb:2211:in `save_without_validation'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/validations.rb:911:in `save_without_dirty'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/dirty.rb:75:in `save_without_transactions'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:106:in `save'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/connection_adapters/abstract/database_statements.rb:
66:in `transaction'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:79:in `transaction'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:98:in `transaction'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:106:in `save'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:118:in `rollback_active_record_state!'
  from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/
active_record/transactions.rb:106:in `save'


Here's the migration I used to prepare things (I checked in the
database to make sure the changes are there):

class AddStatisticTypeVersioning < ActiveRecord::Migration

  def self.up
    create_table :statistic_type_versions do |t|
      t.integer :statistic_type_id, :statistic_category_id
      t.string  :name, :time_filter, :unit
      t.text    :sql
      t.timestamps
    end
    add_column :statistic_types, :version, :integer, :default=>1
  end

  def self.down
    remove_column :statistic_types, :version
    drop_table :statistic_type_versions
  end

end

Am I making some simple mistake?

Many thanks in advance
CHEERS> SAM
Freddy A. (Guest)
on 2008-10-22 00:19
(Received via mailing list)
??

class StatisticsType < ActiveRecord::Base

  version_fu

end
tansaku (Guest)
on 2008-10-22 00:54
(Received via mailing list)
Thanks, but no, have that in there already:

class StatisticType < ActiveRecord::Base
  has_many :statistic_summaries
  version_fu
end
tansaku (Guest)
on 2008-10-24 20:33
(Received via mailing list)
Turns out I was missing a version column in my statistic_types
table ... Duh ....
This topic is locked and can not be replied to.