I have two tables:
books (id, name, desc, instance_id)
instances (id, domain)
A user should ONLY be able to see data that is assigned to their instance_id in records…
For the books, model, to accomplish this, I’m thinking about using a default scope.. Something like:
class Books < ActiveRecord::Base
attr_accessible :name, :description
belongs_to :user
default_scope :order => 'books.created_at DESC'
AND books.instance_id == current.user.instance_id
end
Any thoughts on that idea? Also how can I write that 2nd to last line for Rails 3? ‘AND books.instance_id == current.user.instance_id’
Thanks
It’s not a good idea to access the current user inside the model. I would implement this as follows:
List of Books associated with the user instance:
List of Books created by the user:
Creating a new book:
Note:
Your book creation syntax is wrong. The
buildmethod takes hash as parameter. You are passing two arguments instead of one.OR