Rails: How can I put the sections together to form a book automatically?
I'm a freshman to learn Rails and working on my first project about
"online book writing".
I've already made the MVC of user,book and section. Association like this:
class User < ActiveRecord::Base
has_many :sections , dependent: :destroy
end
class Section < ActiveRecord::Base
belongs_to :book
belongs_to :user
end
class Book < ActiveRecord::Base
has_many :sections
end
So I made a relationship between user and section,but no relationship
between user and book. for example,user.1 write section.1 of book.1 ,the
user.2 write section.2 of book.1.
Then I want to use all the sections of book.1 which written by different
users,to form a book.1 automatically. (connect the text field directly in
one text field,book_content is sum of section_content)
What should I do in the views or models?
No comments:
Post a Comment