When using ruby to generate scaffolding, is there an easy way to add
features that would be useful for keeping track of has_many and
belongs_to relations? For example, suppose I have the following:
Each user has many pages, each site has many pages, each page has many
modules, and also the belongs_to relation holds in the opposite order.
I’m using the acts_as_authenticated plugin, so is there an easy way I
can force the list action in the site controller to list only sites
belonging to the user who is logged in?
I’m doing this right now
@sites = Site.find(:all, :conditions => [ "user_id = ?", current_user.id ])
But I would also have to add checks to the edit, update, and create new
functions that associate each page with the current_user or check if the
particular page belongs to the current_user before allowing him to edit
Likewise, for each page, I would want the scaffold to show and allow
editing only for modules that belong to that particular page which
belongs to the use logged in.
Is there anyway to change the way the belongs to relationship works to
support this? Ideally, I would end up with something like
would show the admistration form to user X only if site 1 belongs to
user X and page 34 belongs to site 1. And it would only list modules
that belong to page 34.