Emmanuel Mtali Emmanuel Mtali - 1 year ago 78
Ruby Question

Structure rails association[user -> one review -> single model]

I have 3 models user, app and review

Current my models have the following associations

User ->

has_many :reviews
has_many :apps

Review ->
belongs_to :app
belongs_to :user

App ->
has_many :reviews
belong_to :user

This allow user to create multiple reviews on a simple app model

My question: How to structure my models so that user can add only one review in a single app model?
How to ensure that user can not add review to app he/she created?

Answer Source

When create the a review/before save you should check if the user do not own the app he/she is reviewing

Check rails cast reputation system from scratch

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download