Chubbs
January 9, 2008, 7:11am
1
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
Chubbs
January 9, 2008, 7:13am
2
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.
Feel free to add me to MSN and/or GTalk as this email.
Chubbs
January 9, 2008, 7:17am
3
mmm but how do i create the route for /room/technology?
Chubbs
January 9, 2008, 7:30am
4
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 ?
Chubbs
January 9, 2008, 7:33am
5
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.
Feel free to add me to MSN and/or GTalk as this email.
Chubbs
January 9, 2008, 7:39am
6
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
Chubbs
January 9, 2008, 9:31am
7
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
Chubbs
January 9, 2008, 7:20am
8
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: frozenplague.net
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.
Feel free to add me to MSN and/or GTalk as this email.