Problems with defining routes

hey i am having problems when defining routes like this.

map.room ‘room/:name’, :controller => ‘room’, :action => ‘show’

when i try goto any url such as:
/room/123
/room/technology

it works fine to goto the show method with a param :name.

but when i want to use my other actions such as ‘list’ it still treats
it as room/:name and will direct it to my show action.

eg.
room/list gives

**NoMethodError in Room#show

Showing room/show.rhtml where line #1 raised:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.name

Try map.resources :room instead.

This will use restful routing which will do exactly what you want it to
do,
but instead list is called “index”.

On Jan 9, 2008 4:40 PM, Chubbs [email protected] wrote:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.name


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

mmm but how do i create the route for /room/technology?

im a bit confused

im just wanting to call the show action for a name for the room.

eg,
/room/technology
should goto /room/show with param[:name] = technology,
so i can show the subtopics within technology

would i have to create a maps.resources for each of my room names ?

No, map.resources :rooms will automatically define the routes you need
for
CRUD’ding resources: index, show, new, create, edit, update & delete.

This means when you do /rooms/technology it’ll actually pass in
“technology”
as params[:id], not params[:name]. Just a minor alteration in your code
should fix this.

On Jan 9, 2008 4:59 PM, Chubbs [email protected] wrote:

would i have to create a maps.resources for each of my room names ?

Whether you do :member or :collection determines whether you do
On Jan 9, 2008 4:46 PM, Chubbs [email protected] wrote:

This will use restful routing which will do exactly what you want it

when i try goto any url such as:
room/list gives
Feel free to add me to MSN and/or GTalk as this email.


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


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

ahh i get you,i change it and got it working

ok ill start using RESTful routing from now on,

thanks for the advice

-chubbs

On Jan 9, 2008, at 7:29 AM, Chubbs wrote:

im just wanting to call the show action for a name for the room.

eg,
/room/technology
should goto /room/show with param[:name] = technology,
so i can show the subtopics within technology

would i have to create a maps.resources for each of my room names ?

Just another detail: you can still have the room name in the URL with
a custom Room#to_param that returns the name, or the trick “#{id}-
name” you can see out there. That parameter goes to params[:id] anyway.

– fxn

Ahh, the wonders of restful routing elude you:

map.resources :room, :member => { :technology => :get }

Or if you’re doing it for a whole bunch of rooms:

map.resources :room, :collection => { :technology => :get }

Whether you do :member or :collection determines whether you do
technology_room_path(@room) or technology_rooms_path(@room).

I covered restful routing a few days ago on this list and wrote a
smallish
tutorial for it: http://frozenplague.net/?p=108

If you have any questions do not hesitate to contact me through the list
or
through GTalk or MSN at this email.

On Jan 9, 2008 4:46 PM, Chubbs [email protected] wrote:

when i try goto any url such as:


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

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