Rails modeling for a user

Posted by Trevor Hartman on Stack Overflow See other posts from Stack Overflow or by Trevor Hartman
Published on 2010-05-20T04:03:33Z Indexed on 2010/05/20 4:10 UTC
Read the original article Hit count: 162

When building a rails app that allows a User to login and create data, is it best to setup a belongs_to :user association on every single model? For example, let's say a user can create Favorites, Colors and Tags.

And let's say Favorites has_many :tags and Colors also has_many :tags. Is it still important for Tags to belong_to :user assuming the User is the only person who has authority to edit those tags?

And a similar question along the same lines: When updating data in FavoritesController, I've come to the conclusion that you perform CRUD operations by always doing something like User.favorites.find(params[:id].update_attributes(param[:favorite]) so that they can definitely only update models that belong to them. Right?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about data-modeling