you and to record every update or you overwrite when there is an update?

On Sat, Sep 11, 2010 at 1:13 PM, nobosh <[email protected]> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to