On 2/22/07, Javan Makhmali <[EMAIL PROTECTED]> wrote:
good idea, that's exactly what i want to do.
On Feb 22, 2007, at 4:12 PM, Nathan Colgate Clark wrote:
> A restful way might be something like this:
>
Along these lines, there are a few ways to get URLs to look exactly
how you want them. This seems like the perfect place to use nested
resources:
With a route like this:
map.resources :category do |category|
category.resources :widgets
end
You'd have URLs like this:
/category/123/widgets
/category/123/widgets/new
...and in your controller you'd have access to params[:category_id]
for free from your routes. In your views you use the
new_widget_path(@category) helper, which generates a URL like
/category/123/widgets/new.
I've done something similar with resources that belong to categories,
and to shorten the URL for the index and show actions I'll usually add
a few custom routes like so:
map.show_category '/widgets/:category_id', :controller => 'widgets',
:action => 'index'
map.show_widget '/widgets/:category_id/:id', :controller => 'widgets',
:action => 'show'
Then you just show_path(@category) or show_widget_path(@category,
@widget) to get URLs like /widgets/123 and /widgets/123/45. (Looks a
little nicer with my friendly_identifier plugin, which I *still*
haven't published yet... stay tuned...)
--
Nick Zadrozny • http://missionsbridge.org/people/nick
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby