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}/ }
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
John, I think it''s just adding: :method => :delete to the destroy definition. -Danimal On Apr 6, 2:52 pm, John Topley <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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}/ } > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Topley
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---