Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1

Nested form modeling rails


I am wondering what my best approach to do what I want to achieve. I have completed the railcasts at http://railscasts.com/episodes/196-nested-model-form-revised but a bit unsured on how to proceed

Here my models

Customer
Book
BookManager

A customer has_many book_manager, in which book_manager has_many books. I am following the nested relationship provided by the railcasts but here my model

Customer       BookManager         Book
ID             Customer_ID         ID
First          Book_ID             Description
Last           isVisible
               isDeleted

The idea is the customer create a new book_description and also set if its visible, and if the customer delete the item, then i want to hide it but also set in the database the book_manager associated with it that its deleted, but not removed at all in the database.

Thanks any suggestion or idea on how to proceed is appreciated


Solution

  • Since it appears that Book is a one-to-one relationship with BookManger, you might want to consider combining the two. Unless, I have misunderstood the relationships. It might make things simpler.

    As for handling the hiding, this is easily done in your controllers/views by accessing the fields you have already: isVisible, and isDeleted. You can even create scopes in your models, such as:

    class BookManager
      scope :active, where(["isVisible = ? AND isDeleted = ?", true, false])