I have following tables with following models:
users(id, role_id) has_many :entries
categories(id, category_name) has_many :entries
entries(id, category_id, user_id) belongs_to :user, belongs_to :category, has_one :storage
storages(id, title, content, entry_id) belongs_to :entry, has_one :vote
votes(id, count, storage_id) belongs_to :storage
Now, when user create new entry(through form) few things must happen:
- New row in entry table will be created(with already existing user_id and category_id)
- New row in storages table will be created(title and content of the post with above entry_id)
- New row in votes table(with above storage_id, count is default 0)
Form for creating new entry must have, combo box for selecting category(like: "Pictures", "Movies", etc), text box for title and text-area for content and nothing more. So here i need only accepts_nested_attributes_for :storage
inside entry model? I dont know what to do with votes, because user will not enter through form anything about votes.
I followed many tutorials and documentation like:
http://railscasts.com/episodes/196-nested-model-form-part-1 and
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for and
answer on my previous question Creation of object which doesn't have model, while creation need to create several entries in other tables
but can't get it how to work.