# Question on routes and default routes

**URL:** <https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910>\
**Category:** Rails\
**Created:** [March 15, 2009, 5:25pm UTC](https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910 "2009-03-15T17:25:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![techwiz18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@techwiz18](https://www.ruby-forum.com/u/techwiz18)\
**Post date:** [March 15, 2009, 5:25pm UTC](https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910/1 "2009-03-15T17:25:29Z")

</div>

Say I have a destroy action configured as the following

map.foo ‘/foos/:id’, :controller =\> ‘foos’, :action =\> ‘show’,  
:conditions =\> { :method =\> :get }  
map.foo ‘/foos/:id’, :controller =\> ‘foos’, :action =\> ‘destroy’,  
:conditions =\> { :method =\> :delete }

Get on foos/:id goes to show and delete on foos/:id goes to destroy.  
Nice and restful so all good so far.

But now say if i have the following default route in my routes.rb

map.connect ‘:controller/:action/:id’

Now someone can explicitly type in the url http://…/foos/destroy/123  
and it will go to my destroy action in controller foos although this  
action should only be accessed by a POST/DELETE not a GET.

Is there anyway to prevent a get on that action other than checking  
within the controller itself?

def destroy  
return home\_url unless method.delete?  
…  
end

Thanks!

---

<div class="post-metadata">

**Author:** ![techwiz18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@techwiz18](https://www.ruby-forum.com/u/techwiz18)\
**Post date:** [March 15, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910/2 "2009-03-15T21:15:13Z")

</div>

Hi,

I’m kind of new to rails, but I’m pretty sure it is suggested that you  
remove those defaults, and only create routes explicitly.

Thanks,  
Brandon

---

<div class="post-metadata">

**Author:** ![techwiz18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@techwiz18](https://www.ruby-forum.com/u/techwiz18)\
**Post date:** [March 15, 2009, 9:35pm UTC](https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910/3 "2009-03-15T21:35:44Z")

</div>

If you are going to go with a Restful design, why not just you  
map.resources?

On Mar 15, 11:25 am, Rails D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![techwiz18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@techwiz18](https://www.ruby-forum.com/u/techwiz18)\
**Post date:** [March 16, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/question-on-routes-and-default-routes/162910/4 "2009-03-16T12:20:02Z")

</div>

It is NOT suggested that the defaults be removed like Brandond says.

It IS suggested that you use map.resources :foos. Which will give you  
what you want.

if you, however, want to check explicitely for the method of and  
action you can do things like:

def some\_action  
render(:text =\> “you shouldnt be trying this”) and return unless  
reques.post?  
…  
…  
end
