nobosh
2010-Sep-11 17:13 UTC
Adding an associated Table to an Existing Table (Book > Revision)
Hello, newbie here... I have the following models: class Instance < ActiveRecord::Base has_many :users has_many :books end class User < ActiveRecord::Base belongs_to :instance end class Book < ActiveRecord::Base belongs_to :instance end I now want to add a BookRevision table, that has the following columns (id, user_id, version # (auto increment), diff (old book copy), timestamps) Logic: 1. When a book is Created, a record is added to the BookRevision table, so we know who created the book in the first place 2. When a book is Updated, a record is added with the user_id (could be a different user), and a new version #, and the old book text, to serve as an archive. Given that I have the Instance, User, Book table implement in my rails add, are these the correct steps to make the above come to life? 1. Add a migration for the BookRevision table.... rails generate migration AddTableBookRevision user_id:integer version:integer diff:text 2. Then update the models as follows: class Instance < ActiveRecord::Base has_many :users has_many :books end class User < ActiveRecord::Base belongs_to :instance end class Book < ActiveRecord::Base belongs_to :instance has_many :BookRevisions end class BookRevision < ActiveRecord::Base belongs_to :Book end Then in my controller, when adding a new book? Right now I have: @book = Book.create(params[:book].merge(:instance_id => current_user.instance_id)) How do I update that to account for the BookRevision association? Thanks for helping me out! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-11 17:34 UTC
Re: Adding an associated Table to an Existing Table (Book > Revision)
you and to record every update or you overwrite when there is an update? On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellman1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, newbie here... > > I have the following models: > > class Instance < ActiveRecord::Base > has_many :users > has_many :books > end > > class User < ActiveRecord::Base > belongs_to :instance > end > > class Book < ActiveRecord::Base > belongs_to :instance > end > > I now want to add a BookRevision table, that has the following columns > (id, user_id, version # (auto increment), diff (old book copy), > timestamps) > > Logic: > 1. When a book is Created, a record is added to the BookRevision > table, so we know who created the book in the first place > 2. When a book is Updated, a record is added with the user_id (could > be a different user), and a new version #, and the old book text, to > serve as an archive. > > > > Given that I have the Instance, User, Book table implement in my rails > add, are these the correct steps to make the above come to life? > 1. Add a migration for the BookRevision table.... > rails generate migration AddTableBookRevision user_id:integer > version:integer diff:text > 2. Then update the models as follows: > > class Instance < ActiveRecord::Base > has_many :users > has_many :books > end > > class User < ActiveRecord::Base > belongs_to :instance > end > > class Book < ActiveRecord::Base > belongs_to :instance > has_many :BookRevisions > end > > class BookRevision < ActiveRecord::Base > belongs_to :Book > end > > > > Then in my controller, when adding a new book? Right now I have: > @book = Book.create(params[:book].merge(:instance_id => > current_user.instance_id)) > How do I update that to account for the BookRevision association? > > Thanks for helping me out! > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Sep-11 17:36 UTC
Re: Adding an associated Table to an Existing Table (Book > Revision)
I want to add a revision record on every update to the book record. Like how a wiki works. Every time the wiki is update it tracks a revision: http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database-schema.png On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> you and to record every update or you overwrite when there is an update? > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, newbie here... > > > I have the following models: > > > class Instance < ActiveRecord::Base > > has_many :users > > has_many :books > > end > > > class User < ActiveRecord::Base > > belongs_to :instance > > end > > > class Book < ActiveRecord::Base > > belongs_to :instance > > end > > > I now want to add a BookRevision table, that has the following columns > > (id, user_id, version # (auto increment), diff (old book copy), > > timestamps) > > > Logic: > > 1. When a book is Created, a record is added to the BookRevision > > table, so we know who created the book in the first place > > 2. When a book is Updated, a record is added with the user_id (could > > be a different user), and a new version #, and the old book text, to > > serve as an archive. > > > Given that I have the Instance, User, Book table implement in my rails > > add, are these the correct steps to make the above come to life? > > 1. Add a migration for the BookRevision table.... > > rails generate migration AddTableBookRevision user_id:integer > > version:integer diff:text > > 2. Then update the models as follows: > > > class Instance < ActiveRecord::Base > > has_many :users > > has_many :books > > end > > > class User < ActiveRecord::Base > > belongs_to :instance > > end > > > class Book < ActiveRecord::Base > > belongs_to :instance > > has_many :BookRevisions > > end > > > class BookRevision < ActiveRecord::Base > > belongs_to :Book > > end > > > Then in my controller, when adding a new book? Right now I have: > > @book = Book.create(params[:book].merge(:instance_id => > > current_user.instance_id)) > > How do I update that to account for the BookRevision association? > > > Thanks for helping me out! > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-11 17:40 UTC
Re: Re: Adding an associated Table to an Existing Table (Book > Revision)
see if this helps http://railscasts.com/episodes/177-model-versioning On Sat, Sep 11, 2010 at 1:36 PM, nobosh <bhellman1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to add a revision record on every update to the book record. > > Like how a wiki works. Every time the wiki is update it tracks a > revision: > http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database-schema.png > > On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > you and to record every update or you overwrite when there is an update? > > > > > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, newbie here... > > > > > I have the following models: > > > > > class Instance < ActiveRecord::Base > > > has_many :users > > > has_many :books > > > end > > > > > class User < ActiveRecord::Base > > > belongs_to :instance > > > end > > > > > class Book < ActiveRecord::Base > > > belongs_to :instance > > > end > > > > > I now want to add a BookRevision table, that has the following columns > > > (id, user_id, version # (auto increment), diff (old book copy), > > > timestamps) > > > > > Logic: > > > 1. When a book is Created, a record is added to the BookRevision > > > table, so we know who created the book in the first place > > > 2. When a book is Updated, a record is added with the user_id (could > > > be a different user), and a new version #, and the old book text, to > > > serve as an archive. > > > > > Given that I have the Instance, User, Book table implement in my rails > > > add, are these the correct steps to make the above come to life? > > > 1. Add a migration for the BookRevision table.... > > > rails generate migration AddTableBookRevision user_id:integer > > > version:integer diff:text > > > 2. Then update the models as follows: > > > > > class Instance < ActiveRecord::Base > > > has_many :users > > > has_many :books > > > end > > > > > class User < ActiveRecord::Base > > > belongs_to :instance > > > end > > > > > class Book < ActiveRecord::Base > > > belongs_to :instance > > > has_many :BookRevisions > > > end > > > > > class BookRevision < ActiveRecord::Base > > > belongs_to :Book > > > end > > > > > Then in my controller, when adding a new book? Right now I have: > > > @book = Book.create(params[:book].merge(:instance_id => > > > current_user.instance_id)) > > > How do I update that to account for the BookRevision association? > > > > > Thanks for helping me out! > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Sep-11 18:03 UTC
Re: Adding an associated Table to an Existing Table (Book > Revision)
Vestal Versions looks pretty impressive, only challenge is it doesn''t seem to play nice with Rails 3. "ActiveRecord::DangerousAttributeError: changes is defined by ActiveRecord" It uses a field in the model called changes. Not sure if there are plans to fix that or not. On Sep 11, 10:40 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> see if this helpshttp://railscasts.com/episodes/177-model-versioning > > > > On Sat, Sep 11, 2010 at 1:36 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I want to add a revision record on every update to the book record. > > > Like how a wiki works. Every time the wiki is update it tracks a > > revision: > >http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database... > > > On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > you and to record every update or you overwrite when there is an update? > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello, newbie here... > > > > > I have the following models: > > > > > class Instance < ActiveRecord::Base > > > > has_many :users > > > > has_many :books > > > > end > > > > > class User < ActiveRecord::Base > > > > belongs_to :instance > > > > end > > > > > class Book < ActiveRecord::Base > > > > belongs_to :instance > > > > end > > > > > I now want to add a BookRevision table, that has the following columns > > > > (id, user_id, version # (auto increment), diff (old book copy), > > > > timestamps) > > > > > Logic: > > > > 1. When a book is Created, a record is added to the BookRevision > > > > table, so we know who created the book in the first place > > > > 2. When a book is Updated, a record is added with the user_id (could > > > > be a different user), and a new version #, and the old book text, to > > > > serve as an archive. > > > > > Given that I have the Instance, User, Book table implement in my rails > > > > add, are these the correct steps to make the above come to life? > > > > 1. Add a migration for the BookRevision table.... > > > > rails generate migration AddTableBookRevision user_id:integer > > > > version:integer diff:text > > > > 2. Then update the models as follows: > > > > > class Instance < ActiveRecord::Base > > > > has_many :users > > > > has_many :books > > > > end > > > > > class User < ActiveRecord::Base > > > > belongs_to :instance > > > > end > > > > > class Book < ActiveRecord::Base > > > > belongs_to :instance > > > > has_many :BookRevisions > > > > end > > > > > class BookRevision < ActiveRecord::Base > > > > belongs_to :Book > > > > end > > > > > Then in my controller, when adding a new book? Right now I have: > > > > @book = Book.create(params[:book].merge(:instance_id => > > > > current_user.instance_id)) > > > > How do I update that to account for the BookRevision association? > > > > > Thanks for helping me out! > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Sep-11 18:30 UTC
Re: Adding an associated Table to an Existing Table (Book > Revision)
To install Vestal Versions, after adding the gem you have to run: "script/generate vestal_versions" not sure if that''s a Rails 3 command so I tried: "rails generate vestal_versions" which gave "Could not find generator vestal_versions" I did check to make sure it was installed: $ bundle show vestal_versions /Users/me/Sites/cline/vestal_versions/ruby/1.8/gems/ vestal_versions-1.0.2 Any ideas on how to install Vestal Versions? thxs again! On Sep 11, 11:03 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Vestal Versions looks pretty impressive, only challenge is it doesn''t > seem to play nice with Rails 3. > > "ActiveRecord::DangerousAttributeError: changes is defined by > ActiveRecord" It uses a field in the model called changes. Not sure if > there are plans to fix that or not. > > On Sep 11, 10:40 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > see if this helpshttp://railscasts.com/episodes/177-model-versioning > > > On Sat, Sep 11, 2010 at 1:36 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I want to add a revision record on every update to the book record. > > > > Like how a wiki works. Every time the wiki is update it tracks a > > > revision: > > >http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database... > > > > On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > you and to record every update or you overwrite when there is an update? > > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, newbie here... > > > > > > I have the following models: > > > > > > class Instance < ActiveRecord::Base > > > > > has_many :users > > > > > has_many :books > > > > > end > > > > > > class User < ActiveRecord::Base > > > > > belongs_to :instance > > > > > end > > > > > > class Book < ActiveRecord::Base > > > > > belongs_to :instance > > > > > end > > > > > > I now want to add a BookRevision table, that has the following columns > > > > > (id, user_id, version # (auto increment), diff (old book copy), > > > > > timestamps) > > > > > > Logic: > > > > > 1. When a book is Created, a record is added to the BookRevision > > > > > table, so we know who created the book in the first place > > > > > 2. When a book is Updated, a record is added with the user_id (could > > > > > be a different user), and a new version #, and the old book text, to > > > > > serve as an archive. > > > > > > Given that I have the Instance, User, Book table implement in my rails > > > > > add, are these the correct steps to make the above come to life? > > > > > 1. Add a migration for the BookRevision table.... > > > > > rails generate migration AddTableBookRevision user_id:integer > > > > > version:integer diff:text > > > > > 2. Then update the models as follows: > > > > > > class Instance < ActiveRecord::Base > > > > > has_many :users > > > > > has_many :books > > > > > end > > > > > > class User < ActiveRecord::Base > > > > > belongs_to :instance > > > > > end > > > > > > class Book < ActiveRecord::Base > > > > > belongs_to :instance > > > > > has_many :BookRevisions > > > > > end > > > > > > class BookRevision < ActiveRecord::Base > > > > > belongs_to :Book > > > > > end > > > > > > Then in my controller, when adding a new book? Right now I have: > > > > > @book = Book.create(params[:book].merge(:instance_id => > > > > > current_user.instance_id)) > > > > > How do I update that to account for the BookRevision association? > > > > > > Thanks for helping me out! > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Ruby on Rails: Talk" group. > > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > > . > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > e@googlegroups.com> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Sep-11 18:35 UTC
Re: Adding an associated Table to an Existing Table (Book > Revision)
Also tried: rails g vestal_versions Could not find generator vestal_versions Anyone out there able to get Vestal Versions working with Rails 3? On Sep 11, 11:30 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> To install Vestal Versions, after adding the gem you have to run: > "script/generate vestal_versions" not sure if that''s a Rails 3 command > so I tried: "rails generate vestal_versions" which gave "Could not > find generator vestal_versions" > > I did check to make sure it was installed: > $ bundle show vestal_versions > /Users/me/Sites/cline/vestal_versions/ruby/1.8/gems/ > vestal_versions-1.0.2 > > Any ideas on how to install Vestal Versions? thxs again! > > On Sep 11, 11:03 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Vestal Versions looks pretty impressive, only challenge is it doesn''t > > seem to play nice with Rails 3. > > > "ActiveRecord::DangerousAttributeError: changes is defined by > > ActiveRecord" It uses a field in the model called changes. Not sure if > > there are plans to fix that or not. > > > On Sep 11, 10:40 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > see if this helpshttp://railscasts.com/episodes/177-model-versioning > > > > On Sat, Sep 11, 2010 at 1:36 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I want to add a revision record on every update to the book record. > > > > > Like how a wiki works. Every time the wiki is update it tracks a > > > > revision: > > > >http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database... > > > > > On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > you and to record every update or you overwrite when there is an update? > > > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hello, newbie here... > > > > > > > I have the following models: > > > > > > > class Instance < ActiveRecord::Base > > > > > > has_many :users > > > > > > has_many :books > > > > > > end > > > > > > > class User < ActiveRecord::Base > > > > > > belongs_to :instance > > > > > > end > > > > > > > class Book < ActiveRecord::Base > > > > > > belongs_to :instance > > > > > > end > > > > > > > I now want to add a BookRevision table, that has the following columns > > > > > > (id, user_id, version # (auto increment), diff (old book copy), > > > > > > timestamps) > > > > > > > Logic: > > > > > > 1. When a book is Created, a record is added to the BookRevision > > > > > > table, so we know who created the book in the first place > > > > > > 2. When a book is Updated, a record is added with the user_id (could > > > > > > be a different user), and a new version #, and the old book text, to > > > > > > serve as an archive. > > > > > > > Given that I have the Instance, User, Book table implement in my rails > > > > > > add, are these the correct steps to make the above come to life? > > > > > > 1. Add a migration for the BookRevision table.... > > > > > > rails generate migration AddTableBookRevision user_id:integer > > > > > > version:integer diff:text > > > > > > 2. Then update the models as follows: > > > > > > > class Instance < ActiveRecord::Base > > > > > > has_many :users > > > > > > has_many :books > > > > > > end > > > > > > > class User < ActiveRecord::Base > > > > > > belongs_to :instance > > > > > > end > > > > > > > class Book < ActiveRecord::Base > > > > > > belongs_to :instance > > > > > > has_many :BookRevisions > > > > > > end > > > > > > > class BookRevision < ActiveRecord::Base > > > > > > belongs_to :Book > > > > > > end > > > > > > > Then in my controller, when adding a new book? Right now I have: > > > > > > @book = Book.create(params[:book].merge(:instance_id => > > > > > > current_user.instance_id)) > > > > > > How do I update that to account for the BookRevision association? > > > > > > > Thanks for helping me out! > > > > > > > -- > > > > > > You received this message because you are subscribed to the Google > > > > Groups > > > > > > "Ruby on Rails: Talk" group. > > > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com > > > > . > > > > > > To unsubscribe from this group, send email to > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > e@googlegroups.com> > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > > > "Ruby on Rails: Talk" group. > > > > To post to this group, send email to rubyonrails-talk@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-12 02:58 UTC
Re: Re: Adding an associated Table to an Existing Table (Book > Revision)
well im going to sleep now but ill check it out tomorrow On Sat, Sep 11, 2010 at 2:35 PM, nobosh <bhellman1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also tried: > > rails g vestal_versions > Could not find generator vestal_versions > > Anyone out there able to get Vestal Versions working with Rails 3? > > On Sep 11, 11:30 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > To install Vestal Versions, after adding the gem you have to run: > > "script/generate vestal_versions" not sure if that''s a Rails 3 command > > so I tried: "rails generate vestal_versions" which gave "Could not > > find generator vestal_versions" > > > > I did check to make sure it was installed: > > $ bundle show vestal_versions > > /Users/me/Sites/cline/vestal_versions/ruby/1.8/gems/ > > vestal_versions-1.0.2 > > > > Any ideas on how to install Vestal Versions? thxs again! > > > > On Sep 11, 11:03 am, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Vestal Versions looks pretty impressive, only challenge is it doesn''t > > > seem to play nice with Rails 3. > > > > > "ActiveRecord::DangerousAttributeError: changes is defined by > > > ActiveRecord" It uses a field in the model called changes. Not sure if > > > there are plans to fix that or not. > > > > > On Sep 11, 10:40 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > see if this helpshttp://railscasts.com/episodes/177-model-versioning > > > > > > On Sat, Sep 11, 2010 at 1:36 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I want to add a revision record on every update to the book record. > > > > > > > Like how a wiki works. Every time the wiki is update it tracks a > > > > > revision: > > > > > > http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database... > > > > > > > On Sep 11, 10:34 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > you and to record every update or you overwrite when there is an > update? > > > > > > > > On Sat, Sep 11, 2010 at 1:13 PM, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > Hello, newbie here... > > > > > > > > > I have the following models: > > > > > > > > > class Instance < ActiveRecord::Base > > > > > > > has_many :users > > > > > > > has_many :books > > > > > > > end > > > > > > > > > class User < ActiveRecord::Base > > > > > > > belongs_to :instance > > > > > > > end > > > > > > > > > class Book < ActiveRecord::Base > > > > > > > belongs_to :instance > > > > > > > end > > > > > > > > > I now want to add a BookRevision table, that has the following > columns > > > > > > > (id, user_id, version # (auto increment), diff (old book copy), > > > > > > > timestamps) > > > > > > > > > Logic: > > > > > > > 1. When a book is Created, a record is added to the > BookRevision > > > > > > > table, so we know who created the book in the first place > > > > > > > 2. When a book is Updated, a record is added with the user_id > (could > > > > > > > be a different user), and a new version #, and the old book > text, to > > > > > > > serve as an archive. > > > > > > > > > Given that I have the Instance, User, Book table implement in > my rails > > > > > > > add, are these the correct steps to make the above come to > life? > > > > > > > 1. Add a migration for the BookRevision table.... > > > > > > > rails generate migration AddTableBookRevision > user_id:integer > > > > > > > version:integer diff:text > > > > > > > 2. Then update the models as follows: > > > > > > > > > class Instance < ActiveRecord::Base > > > > > > > has_many :users > > > > > > > has_many :books > > > > > > > end > > > > > > > > > class User < ActiveRecord::Base > > > > > > > belongs_to :instance > > > > > > > end > > > > > > > > > class Book < ActiveRecord::Base > > > > > > > belongs_to :instance > > > > > > > has_many :BookRevisions > > > > > > > end > > > > > > > > > class BookRevision < ActiveRecord::Base > > > > > > > belongs_to :Book > > > > > > > end > > > > > > > > > Then in my controller, when adding a new book? Right now I > have: > > > > > > > @book = Book.create(params[:book].merge(:instance_id => > > > > > > > current_user.instance_id)) > > > > > > > How do I update that to account for the BookRevision > association? > > > > > > > > > Thanks for helping me out! > > > > > > > > > -- > > > > > > > You received this message because you are subscribed to the > Google > > > > > Groups > > > > > > > "Ruby on Rails: Talk" group. > > > > > > > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > > > . > > > > > > > To unsubscribe from this group, send email to > > > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com><rubyonrails-talk%2Bunsubscrib > > > > > e@googlegroups.com> > > > > > > > . > > > > > > > For more options, visit this group at > > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > Groups > > > > > "Ruby on Rails: Talk" group. > > > > > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > > To unsubscribe from this group, send email to > > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.