> I have this model.
> 
> city has_many stores
> store belongs_to city
> 
> I created resources for them and mapped them as such, using nested
> resources:
> 
> map.resources :cities, :has_many => :stores
> 
> But I wanted to make the stores available independant from the city,
> so I added:
I think about nested resources as a way to scope (or protect) access 
through another. In a previous framework that I used these were referred 
to as "owned" objects. These "owned" objects would be ones that don't 
make sense, or have no value, apart from their "owner."

Take "comments" for example: A comment might be related to a blog post. 
The comment has no real value apart from the post. It, therefore, makes 
a lot of sense to have access to the "comment" only through the related 
post.

However, in cases where a resource has value on it own. For example an 
employee might belong to a department, but the employee object has value 
completely apart from a department. Therefore, it makes sense for an 
employee object to be managed directly rather than though a department.

This later case sounds more like what you have. It would still be fine I 
suppose to nest it, but I don't think I would. I think I would use a 
more direct approach for accessing the "stores" collection like simply 
going through the association from city.

Don't confuse nested resources with associations. They are not the same 
thing, even though they both share the has_many and belong_to syntax. 
You don't need nested resources everywhere your model has an 
association.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to