Question About Scaffolding for My First Rails App


#1

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:

Users
Sites
Pages
Modules

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
it.

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

/sites/1/page/34/list
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.


#2

Andrew K. wrote:

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
it.

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

/sites/1/page/34/list
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.

http://wiki.rubyonrails.org/rails/pages/Scaffolding+Extensions+Plugin


#3

joey__ wrote:

http://wiki.rubyonrails.org/rails/pages/Scaffolding+Extensions+Plugin

Thanks, this looks solid.