2
votes

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.

1

1 Answers

1
votes

In reading your question I am not quite sure what you are after.

If you are using nested attributes one other thing to keep in mind is the routing (which may or may not matter depending on how you are setting up the relationships)

ie:

resources :users do
 resources :entries
end

I know it has gotten me before :)

From my understanding of what you are asking, you should be able to do everything you need with nested attributes.

If you want some additional info I would recommend posting your code along with the errors you are getting in setting up the relationship.