Rails can't find my route but it exists!

Posted by DJTripleThreat on Stack Overflow See other posts from Stack Overflow or by DJTripleThreat
Published on 2010-05-30T18:37:01Z Indexed on 2010/05/30 18:42 UTC
Read the original article Hit count: 255

Ok I have events that I want to publish/unpublish with an extra action (nonRESTful) I watched Ryan Bates' railscast on this: http://railscasts.com/episodes/35-custom-rest-actions and it got me most of the way. I think the problem is that my route is nested in an /admin section so even though when I run rake routes and get:

publish_admin_event PUT /admin/events/:id/publish(.:format) {:controller=>"event_services", :action=>"publish"}

This won't work in my /views/admin/index.html.erb file:

<%= link_to 'Publish', publish_admin_event(event), :method => :put %>

because it claims that path doesn't exist! And neither will this:

<%= link_to 'Publish', {:controller => :event_services, :action => :publish}, {:method => :put, :id => event} %>

and says that "No route matches {:controller=>"event_services", :action=>"publish"}"

so what gives? (And I've tried restarting my server so that isn't it.)

EDIT: This DOES work:

<%= link_to 'Publish', "/admin/events/" + event.id.to_s + "/publish", :method => :put %> 

But I'd rather NOT do this.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about custom-routes