mardi 16 février 2016

Routes on Rails application are failing

I'm taking an MOOC and the goal of this exercise is to add a new functionality to typo, where i can merge two articles together.

When I add the route to my new function merge to the routes.rb I'm losing the functionality to delete articles. I think something clashes here, but I have no idea what.

The original routes.rb:

%w{advanced cache categories comments content profiles feedback general pages
resources sidebar textfilters themes trackbacks users settings tags redirects seo post_types }.each do |i|
  match "/admin/#{i}", :to => "admin/#{i}#index", :format => false
  match "/admin/#{i}(/:action(/:id))", :to => "admin/#{i}", :action => nil, :id => nil, :format => false
end

This method in articles.rb creates the correct url for deleting

def delete_url
 blog.url_for(:controller => "/admin/content", :action =>"destroy",:id => id)
end

correct url:

http://ift.tt/1U5vZLX

If i follow this link i can successfully delete an article.

However, if I add the following before that to my routes.rb:

namespace "admin" do
 resources :content do
   post :merge, on: :member, as: :merge
 end
end

The new merging functionality and forms are working fine, but the method delete_url now produces something like this:

http://ift.tt/1VjDLQG

and if I follow a link created by this method i get:

Unknown action

The action 'show' could not be found for Admin::ContentController

Maybe I'm overwriting something? I can't figure out what's happening here and why this affects the delete action / route.

Thanks in advance!

EDIT: rake routes | grep content:

with the original routes.rb gives me:

admin_content        /admin/content                     {:controller=>"admin/content", :action=>"index"}
                     /admin/content(/:action(/:id))     {:action=>nil, :id=>nil, :controller=>"admin/content"}

whereas my modified routes.rb produces

merge_admin_content POST   /admin/content/:id/merge(.:format) {:action=>"merge", :controller=>"admin/content"}
admin_content_index GET    /admin/content(.:format)           {:action=>"index", :controller=>"admin/content"}
                   POST   /admin/content(.:format)           {:action=>"create", :controller=>"admin/content"}
 new_admin_content GET    /admin/content/new(.:format)       {:action=>"new", :controller=>"admin/content"}
edit_admin_content GET    /admin/content/:id/edit(.:format)  {:action=>"edit", :controller=>"admin/content"}
     admin_content GET    /admin/content/:id(.:format)       {:action=>"show", :controller=>"admin/content"}
                   PUT    /admin/content/:id(.:format)       {:action=>"update", :controller=>"admin/content"}
                   DELETE /admin/content/:id(.:format)       {:action=>"destroy", :controller=>"admin/content"}
                          /admin/content                     {:controller=>"admin/content", :action=>"index"}
                          /admin/content(/:action(/:id))     {:action=>nil, :id=>nil, :controller=>"admin/content"}

Aucun commentaire:

Enregistrer un commentaire