I’m trying to follow this example.
I’ve created an action in my controller:
def distribute_resume
Rails.logger.info(distribution_id.to_s)
PartnerNotifier.distribute_resume(distribution_id)
flash[:notice] = "Successfully distributed resume"
redirect_to admin_distributions_workflows_path
end
and I created a route in my `config/routes.rb’ file:
namespace :admin do
namespace :distributions do
resources :workflows do
collection do
post :edit_multiple
put :update_multiple
post :distribute_resume
end
end
end
end
I also tried moving the route to the action outside of the collection block like this:
namespace :admin do
namespace :distributions do
resources :workflows do
post :distribute_resume
collection do
post :edit_multiple
put :update_multiple
end
end
end
end
But i’m getting this error in both cases:
No route matches {:controller=>"admin/distributions/workflows_controller", :distribution_id=>123, :action=>"distribute_resume", :method=>:post}
I’m too green to figure this out.
update:
ah yes, need to remember to check rake routes more often. I do see this:
admin_distributions_workflow_distribute_resume POST /admin/distributions/workflows/:workflow_id/distribute_resume(.:format) {:action=>"distribute_resume", :controller=>"admin/distributions/workflows"}
so I changed my view:
<%=link_to "Send this resume to #{distribution.matching_profile.partner.email}",
:controller => "workflows", <-- instead of "workflows_controller"
:action => "distribute_resume",
:distribution_id => distribution.id,
:method => :post%>
but i’m still getting a similar error message:
No route matches {:controller=>"admin/distributions/workflows", :distribution_id=>121, :action=>"distribute_resume", :method=>:post}
Two issues:
First
You are not passing in
:workflow_idduring your POST request. If you look at yourrake routesresults, you’ll see it is necessary:Second
When you namespace the routes like that, you are telling it that you have also reflected that namespacing within the Controller as well.
So
Means that you would need to do this in your controller:
If you’d rather not namespace your controllers like that, then you need to switch up your routing syntax to instead be:
which will still give you the same routing scheme but will not force you to do the controller module prefixes like before. Keep in mind if you switch to the scoped method, your path names will change so run
rake routesto get the new ones.More info: http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
Update:
I think you’re making this a little more complicated then it needs to be. Your
link_tocan be simplified to this: