technoweenie / acts_as_versioned Goto Github PK
View Code? Open in Web Editor NEWActiveRecord plugin for versioning your models.
License: MIT License
ActiveRecord plugin for versioning your models.
License: MIT License
= acts_as_versioned This library adds simple versioning to an ActiveRecord module. ActiveRecord is required. == Resources Install * gem install acts_as_versioned <3 GitHub * http://github.com/technoweenie/acts_as_versioned Gemcutter FTW * http://gemcutter.org/gems/acts_as_versioned Subversion * http://svn.github.com/technoweenie/acts_as_versioned.git Special thanks to Dreamer on ##rubyonrails for help in early testing. His ServerSideWiki (http://serversidewiki.com) was the first project to use acts_as_versioned <em>in the wild</em>.
there can be multiple version that requires approval. how do i set the versions to show only the approved version. Versions can be approved by admin
there can be multiple version that requires approval. how do i set the versions to show only the approved version. Versions can be approved by admin of a moderator has to approve all versions
This line should be fixed
On running the following migrations:
class AddVersionToPost < ActiveRecord::Migration def self.up Post.create_versioned_table end def self.down Post.drop_versioned_table end end
and where Post is:
class Post acts_as_versioned end
Steps to reproduce:
Create a new Rails app with a single model named "bill.rb" with acts_as_versioned .
Set config/database.yml to use MySQL
Generate a migration called "create_bills".
In this migration, create a table named "bill" with a single attribute named "amount" with a "decimal" datatype. Include the "Bill.create_versioned_table" line.
Try "rake db:migrate" (db:drop & db:create as needed).
Note: No integer type has byte size 10 rake aborted! error
Add a specification of :scale => 2 to the migration datatype specification. The error remains.
Add a specification of :precision => 8 (even without :scale). The error disappears.
Tested on OSX 10.5.8, Ruby 1.8.6, Rails 2.3.3, acts_as_versioned 0.2.3
When saving a versioned model for the first time, a version is created regardless of the :if
condition.
E.g. if I do
acts_as_versioned :if => Proc.new {|item| false}
I will still get a new record in the _versions
table when calling the first save()
(or create()
) on my model.
I suppose there's a reason for this, but from my point of view when the :if
condition is false no version should be saved, ever.
I think the behavior stems from line 391 in acts_as_versioned.rb
.
@saving_version = new_record? || save_version?
Why do new records get to bypass the version saving conditions?
acts_as_versioned should determine which columns to version, based on the #{model}_versions table.
The documentation for ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned says:
The _versions table should contain all the fields you want versioned
but this is clearly not the case (with version 0.5.2). For any attributes missing in the _versions table, I get:
undefined method
attribute=' for #Model::Version:0x180dfe4 vendor/acts_as_versioned/lib/acts_as_versioned.rb:331:in
send'
vendor/acts_as_versioned/lib/acts_as_versioned.rb:331:inclone_versioned_model' vendor/acts_as_versioned/lib/acts_as_versioned.rb:330:in
each'
vendor/acts_as_versioned/lib/acts_as_versioned.rb:330:inclone_versioned_model' vendor/acts_as_versioned/lib/acts_as_versioned.rb:273:in
save_version'
despite the fact that gem option is switched on at this repo, gem technoweenie-acts_as_versioned cannot be found :(
can t figure it out, need some help
undefined method table_exists?' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x48ac664> D:/WebApp/payr/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb:412:in
create_versioned_table'
rails 1.2.3
ps. I m trying to run the example application of ruport - payr, too many places to fix!
Error in a Rails 3.0.1 project:
Bundler could not find compatible versions for gem "activerecord": In Gemfile: rails (= 3.0.1) depends on activerecord (= 3.0.1) acts_as_versioned depends on activerecord (3.0.0) (Bundler::VersionConflict)
Rails >= 3.0.3 aborts migrations if they try to create an index with a name are longer than 64 characters on PostgreSQL or MySQL (yes, 64, not 63 like the error says).
When acts_as_versioned creates indexes, it does not check the length of the resulting index name.
The patch below fixes that. It fixes the problem on MySQL and PostgreSQL (I tested both).
--- acts_as_versioned.rb 2011-05-06 11:37:30.000000000 -0400 +++ acts_as_versioned.rb 2011-05-06 11:29:47.000000000 -0400 @@ -440,7 +440,9 @@ :precision => type_col.precision end - self.connection.add_index versioned_table_name, versioned_foreign_key + # Make sure not to create an index that is too long (postgres limits index names to 64 characters) + name = 'index_' + versioned_table_name + '_on_' + versioned_foreign_key + self.connection.add_index versioned_table_name, versioned_foreign_key, :name => name[0,63] end # Rake migration task to drop the versioned table
add md format to your README file
SomeModel.versions.first.some_association.anything doesn't work, even though the association itself is found just fine.
I'm not sure how to fix this; it presumably has something to do with inheritance chaining...
Example 1:
>> User.find(Profile.last.versions.last.user_id)
=> #<User id: 1, login: "saizai", ...
>> Profile.last.user
=> #<User id: 1,
>> Profile.last.versions.last.user
NoMethodError: undefined method `user' for #<Profile::Version:0x25fdc30>
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:260:in `method_missing'
Example 2:
>> Profile.last.versions.last.updater
=> #<User id: 1, login: "saizai", ...
>> Profile.last.versions.last.updater.name
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?'
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:71:in `each'
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:351:in `respond_to?'
from /Users/saizai/Dropbox/workspace/hyperdictionary/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:213:in `method_missing'
from (irb):99
from :0
>> User.find(Profile.last.versions.last.updater_id)
=> #<User id: 1, login: "saizai", ...
>> User.find(Profile.last.versions.last.updater_id).name
=> "Rootage"
>> Profile.last.versions.last
=> #<Profile::Version id: 2, ...
>> Profile.last.versions.last.skip_time_zone_conversion_for_attributes
=> []
>> Profile.last.versions.last.updater.skip_time_zone_conversion_for_attributes
=> nil
>> User.find(Profile.last.versions.last.updater_id).skip_time_zone_conversion_for_attributes
=> []
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.