Alias resource route

Hi. I have a resource named item. So in my routes.rb I have:

map.resources :item

and I can go to http://localhost:3000/items and see all my items

If I go to /items/1 and see details for item 1 since I am routed to the
show action, etc.

This is great but I would also like users to be able to go to a
different route as well as item - say myitems. So if a user types in
/items or /myitems I want them to go to the same place - controller =>
items, :action => index

I can define an individual route for each route like:

map.connect ‘myitems’, :controller => ‘items’, :action => ‘index’
map.connect ‘myitems/:id’, :controller => ‘items’, :action => …

but this is not nearly as nice as :resources where I get all those
routes created automatically. Can anyone help with this?

If you want to get all the pre-established routes for your “myitems”
controller then what you want to do is:

map.resources :myitems, :controller => “items”


Thiago J.
http://www.railsfreaks.com

On May 13, 12:11 pm, Explore A. [email protected]

And then what’s stopping that user from typing in an ID and showing an
item
that should not be in “myitems”. More security please.

On Wed, May 14, 2008 at 6:49 AM, Thiago J. [email protected]
wrote:

but this is not nearly as nice as :resources where I get all those
routes created automatically. Can anyone help with this?

Posted viahttp://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Thiago J. wrote:

If you want to get all the pre-established routes for your “myitems”
controller then what you want to do is:

map.resources :myitems, :controller => “items”


Thiago J.
http://www.railsfreaks.com

On May 13, 12:11 pm, Explore A. [email protected]

Thiago,

Thanks very much. This was exactly what I was looking for. It works
perfectly!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs