RESTful Routing

I am new to the routing scheme for RESTful actions on the edge. I am
trying to stray off of the CRUD path a little here and finding the
terrain a little bumpy.

I am trying to call the method TopicsController#toggle_lock. Topics
belong to Forums, so we have this structure in the routes.rb:

map.resources :forums do |forum|
forum.resources :topics do |topic|
topic.resources :posts
topic.resources :member => { :toggle_lock => :get }
end
end

when I try to hit http://localhost/forums/1/topics/5;toggle_lock I get a
404.

What am I doing wrong?

What is the best way to test this stuff?

Got it to work!

map.resources :forums do |forum|
forum.resources :topics do |topic|
topic.resources :posts
end
forum.resources :topics, :member => { :toggle_lock => :post }
end

And since there aren’t any examples out there with tests, here is my
test:

def test_should_toggle_lock
login_as :aaron
post :toggle_lock, :forum_id => forums(:comics).id, :id =>
topics(:galactus).id
assert_redirected_to topic_path(forums(:comics), topics(:galactus))
assert_equal ‘Topic has been locked.’, flash[:notice]
end

Carl F. wrote:

I am new to the routing scheme for RESTful actions on the edge. I am
trying to stray off of the CRUD path a little here and finding the
terrain a little bumpy.

I am trying to call the method TopicsController#toggle_lock. Topics
belong to Forums, so we have this structure in the routes.rb:

map.resources :forums do |forum|
forum.resources :topics do |topic|
topic.resources :posts
topic.resources :member => { :toggle_lock => :get }
end
end

when I try to hit http://localhost/forums/1/topics/5;toggle_lock I get a
404.

What am I doing wrong?

map.resources :forums do |forum|
forum.resources :topics, :member => { :toggle_lock => :get } do
|topic|
topic.resources :posts
end
end

What is the best way to test this stuff?

Get Rick “technoweenie” Olson’s routing_navigator plugin.

script/plugin install routing_navigator


Josh S.
http://blog.hasmanythrough.com

Thank you Josh!