# RESTful Named Routes

**URL:** <https://www.ruby-forum.com/t/restful-named-routes/134021>\
**Category:** Rails\
**Created:** [April 6, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/restful-named-routes/134021 "2008-04-06T22:52:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [April 6, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/restful-named-routes/134021/1 "2008-04-06T22:52:41Z")

</div>

Hi,

I’m writing a blog engine using Rails and have removed the default route  
because I want to use RESTful URLs that have the form /yyyy/mm/dd/slug

I’ve added some named routes for showing and editing posts that work  
fine. The problem is that my named route for deleting a post isn’t  
working - the destroy action within my Posts controller is never called.  
If I run “rake routes” then I notice that my delete\_post\_by\_slug route  
doesn’t have a DELETE method against it.

How can I constrain my delete\_post\_by\_slug route to the HTTP DELETE  
verb?

Thanks for any help!

John

Below is an extract from my routes.rb file:

map.resources :users  
map.resources :posts  
map.resource :session, :controller =\> ‘session’

# Edit

map.edit\_post\_by\_slug ‘/:year/:month/:day/:slug/edit’, :controller =\>  
‘posts’,  
:action =\> ‘edit’, :requirements =\> { :year =\> /\d{4}/,  
:month =\> /\d{1,2}/,  
:day =\> /\d{1,2}/ }

# Show

map.post\_by\_slug ‘/:year/:month/:day/:slug’, :controller =\> ‘posts’,  
:action =\> ‘show’, :requirements =\> { :year =\> /\d{4}/,  
:month =\> /\d{1,2}/,  
:day =\> /\d{1,2}/ }

# Destroy

map.delete\_post\_by\_slug ‘/:year/:month/:day/:slug’, :controller =\>  
‘posts’,  
:action =\> ‘destroy’, :requirements =\> { :year =\> /\d{4}/,  
:month =\> /\d{1,2}/,  
:day =\> /\d{1,2}/ }

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [April 7, 2008, 12:59am UTC](https://www.ruby-forum.com/t/restful-named-routes/134021/2 "2008-04-07T00:59:34Z")

</div>

John,

I think it’s just adding: :method =\> :delete  
to the destroy definition.

-Danimal

On Apr 6, 2:52 pm, John T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [April 7, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/restful-named-routes/134021/3 "2008-04-07T20:29:41Z")

</div>

Hi Danimal,

I figured it out. You were pretty much right, but the syntax is  
:conditions =\> { :method =\> :delete }

Thanks for your help!

John

Danimal wrote:

> John,
> 
> I think it’s just adding: :method =\> :delete  
> to the destroy definition.
> 
> -Danimal
> 
> On Apr 6, 2:52 pm, John T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
