I am building a photo gallery app in Rails (following this guide). I would like to expand on the app this guide builds by adding Devise user authentication and storing who uploads each photo. I have got Devise running nicely but I'm not sure what the best way to keep track of who uploads what. This is what I'm thinking:
class User < ActiveRecord::Base
has_many :photos
...
end
class Photo < ActiveRecord::Base
belongs to :user
...
end
class AddUserToPhotos < ActiveRecord::Migration
def change
add_column :photos, :user_id, :integer
end
end
The above (as I understand it) would store the uploader in each photo record and as an added bonus, allow us to run @user.photos
to see all of a users photos regardless of gallery.
Is this the best way to do this?