Forum: Ruby on Rails Question About Scaffolding for My First Rails App

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5886e893080c81d28a0cca9fb2068207?d=identicon&s=25 ar ko (kortina)
on 2006-03-23 04:57
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
<pre>
    @sites = Site.find(:all, :conditions => [ "user_id = ?",
current_user.id ])
</pre>

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.
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-03-23 08:54
Andrew Kortina 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/Scaffoldin...
5886e893080c81d28a0cca9fb2068207?d=identicon&s=25 ar ko (kortina)
on 2006-03-23 21:26
joey__ wrote:

> http://wiki.rubyonrails.org/rails/pages/Scaffoldin...

Thanks, this looks solid.
This topic is locked and can not be replied to.