REST - Nested Resources

  1. Yes, you can have your resource appear in the resource map as many
    times as you like. Just a word of warning, though. The more times
    that it appears in the map, the more complex your controller can/will
    become; you’ll have to be prepared to handle a request from ANY of
    those paths. You may limit the footprint through your UI but that
    could be circumvented by the person who’s watching your pretty URLs.

  2. Yes, you can pass multiple parameters. For an oversimplified
    example, think about the update path. You’ve probably got at least as
    many parameters as columns getting posted with each update request.
    In your case you might have several UI’s related to them that make
    them appear to be a “Complete the milestone” and a “Create the
    milestone” or a “Fix an error in the milestone” path, but they’re all
    fundamentally updates coming with potentially different set of
    “filters”.

The key point with REST is that you have a resource at a known address
that responds in a known way, setting or getting state, each time to
call it on that address. In this case, you milestones#index is going
to respond with a list of milestones every single time. In some cases
it’s the complete list (not nested), in some cases it’s a list bound
by a user, and in other cases it’s further filtered (or sorted…)
based on the parameters you send up. The big deal, though is that
it’s always reporting back on the state of the collection.

  1. Obie’s is the best overall source I’ve read so far. I have not yet
    seen the Agile 3ed that’s out in Beta but I’d bet it has a fair
    covering of it, too. Rails Advanced Recipes is a good resource but
    it’s not specifically devoted to REST.

AndyV wrote:

  1. Yes, you can have your resource appear in the resource map as many
    times as you like. Just a word of warning, though. The more times
    that it appears in the map, the more complex your controller can/will
    become; you’ll have to be prepared to handle a request from ANY of
    those paths. You may limit the footprint through your UI but that
    could be circumvented by the person who’s watching your pretty URLs.

    Thanks Andy - this is has helped me a lot :wink:

@Chuck: You need to override the to_param method in your User class

class User
has_many :locations

def to_param
username
end
end

then in controller

User.find_by_username(params[:id])

in views
<%= link_to @user, ‘test’ %> results in test</
a>

you can definitely use a regex in your routes to restrict what is
captured, but its not necessary for it to work.

Can anybody tell me how I can use a login instead of id in my route?

/users/chuck/locations/

Can that be generated by a regular nested route identifier like
users_locations_path?

Thanks,

Chuck