views:

94

answers:

1

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.

EDIT #2: My route entry:

map.resource :admin do |admin|
  admin.admin '', :controller => :admin, :only => :index
  admin.resources :events, :controller => :event_services, :member => {:publish => :put } do |service_event|
    # ...
  end
end
+3  A: 

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!

I'd rather expect it not to work because of a NoMethodError. I think you meant to write publish_admin_event_path instead of just publish_admin_event there. Then it should work.

And neither will this:

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

This will work if you do :controller => "/admin/event_services" (though that isn't necessary if you're already in the admin namespace) and, as you figured out in your comment, move :id => event into the first hash.

sepp2k
That first part worked! I don't know what I forgot the `_path` part! The second part doesn't work. See my second edit.
DJTripleThreat
ok the second works if i leave :controller => :event_services and put my :id => event into the first hash.
DJTripleThreat
@DJTripleThreat: Oops, I didn't see that. Yes, event_services will work if you're already in the admin namespace. `admin/event_services` will work when you're in the top-level namespace. And `/admin/event_services` will work no matter where you are.
sepp2k