0
votes

I keep getting this error when trying to view a page.

ActionView::Template::Error (No route matches {:controller=>"classifieds", :action=>"edit", :id=>#}): 40: <%= h classified.category.name %> 41: <%= h classified.subcategory.name %> 42: <%= h classified.status %> 43: <%= link_to "Edit", edit_classified_path(classified)%> 44: <%= link_to 'Destroy', classified, :confirm => 'Are you sure?', :method => :delete %> 45: <%= check_box_tag 'remove[id][]', classified.id, false %> 46:

routes file

Rails3::Application.routes.draw do
    resources :main, :categories, :cities, :users, :subcategories, :classifieds
    resource :user

    root :to => 'main#index'
    match ':controller(/:action(/:id(.:format)))'

    # route for simple captcha
    match '/simple_captcha/:action', :controller => 'simple_captcha'

    #admin logout
    match '/logout', :controller=>'users', :action=>'destroy'
    match '/login',  :controller=>'users', :action=>'show'

    match '/adminsearch', :controller=>'classifieds', :action=>'adminsearch'

    #search
    match '/mainsearch', :controller=>'main', :action=>'mainsearch'
    match '/:permalink_1/categorysearch', :controller=>'main', :action=>'categorysearch'

    match '/contactadvertiser', :controller=>'main', :action=>'contactadvertiser'

    #city page
    match '/:permalink_1', :controller => 'main', :action => 'city'
    match '/edit', :controller => 'cities', :action => 'edit'

    #activate, edit classifieds
    match '/activate/:activation_code', :controller => 'main', :action => 'activate'
    match '/edit/:activation_code', :controller => 'classifieds', :action => 'edit'
    match '/update/:activation_code', :controller => 'classifieds', :action => 'update'
    match '/delete/:activation_code', :controller => 'classifieds', :action => 'destroy'
    match '/classifieds/multidelete', :controller=>'classifieds', :action=>'delete_multiple'



    #category page
    match '/:permalink_1/:permalink_2', :controller => 'main', :action => 'category'

    #ad page
    match '/:permalink_1/:permalink_2/:permalink_3', :controller => 'classifieds', :action => 'show'

end

rake routes:

             main_index GET    /main(.:format)                        {:controller=>"main", :action=>"index"}
                        POST   /main(.:format)                        {:controller=>"main", :action=>"create"}
               new_main GET    /main/new(.:format)                    {:controller=>"main", :action=>"new"}
              edit_main GET    /main/:id/edit(.:format)               {:controller=>"main", :action=>"edit"}
                   main GET    /main/:id(.:format)                    {:controller=>"main", :action=>"show"}
                        PUT    /main/:id(.:format)                    {:controller=>"main", :action=>"update"}
                        DELETE /main/:id(.:format)                    {:controller=>"main", :action=>"destroy"}
             categories GET    /categories(.:format)                  {:controller=>"categories", :action=>"index"}
                        POST   /categories(.:format)                  {:controller=>"categories", :action=>"create"}
           new_category GET    /categories/new(.:format)              {:controller=>"categories", :action=>"new"}
          edit_category GET    /categories/:id/edit(.:format)         {:controller=>"categories", :action=>"edit"}
               category GET    /categories/:id(.:format)              {:controller=>"categories", :action=>"show"}
                        PUT    /categories/:id(.:format)              {:controller=>"categories", :action=>"update"}
                        DELETE /categories/:id(.:format)              {:controller=>"categories", :action=>"destroy"}
                 cities GET    /cities(.:format)                      {:controller=>"cities", :action=>"index"}
                        POST   /cities(.:format)                      {:controller=>"cities", :action=>"create"}
               new_city GET    /cities/new(.:format)                  {:controller=>"cities", :action=>"new"}
              edit_city GET    /cities/:id/edit(.:format)             {:controller=>"cities", :action=>"edit"}
                   city GET    /cities/:id(.:format)                  {:controller=>"cities", :action=>"show"}
                        PUT    /cities/:id(.:format)                  {:controller=>"cities", :action=>"update"}
                        DELETE /cities/:id(.:format)                  {:controller=>"cities", :action=>"destroy"}
                  users GET    /users(.:format)                       {:controller=>"users", :action=>"index"}
                        POST   /users(.:format)                       {:controller=>"users", :action=>"create"}
               new_user GET    /users/new(.:format)                   {:controller=>"users", :action=>"new"}
              edit_user GET    /users/:id/edit(.:format)              {:controller=>"users", :action=>"edit"}
                   user GET    /users/:id(.:format)                   {:controller=>"users", :action=>"show"}
                        PUT    /users/:id(.:format)                   {:controller=>"users", :action=>"update"}
                        DELETE /users/:id(.:format)                   {:controller=>"users", :action=>"destroy"}
          subcategories GET    /subcategories(.:format)               {:controller=>"subcategories", :action=>"index"}
                        POST   /subcategories(.:format)               {:controller=>"subcategories", :action=>"create"}
        new_subcategory GET    /subcategories/new(.:format)           {:controller=>"subcategories", :action=>"new"}
       edit_subcategory GET    /subcategories/:id/edit(.:format)      {:controller=>"subcategories", :action=>"edit"}
            subcategory GET    /subcategories/:id(.:format)           {:controller=>"subcategories", :action=>"show"}
                        PUT    /subcategories/:id(.:format)           {:controller=>"subcategories", :action=>"update"}
                        DELETE /subcategories/:id(.:format)           {:controller=>"subcategories", :action=>"destroy"}
            classifieds GET    /classifieds(.:format)                 {:controller=>"classifieds", :action=>"index"}
                        POST   /classifieds(.:format)                 {:controller=>"classifieds", :action=>"create"}
         new_classified GET    /classifieds/new(.:format)             {:controller=>"classifieds", :action=>"new"}
        edit_classified GET    /classifieds/:id/edit(.:format)        {:controller=>"classifieds", :action=>"edit"}
             classified GET    /classifieds/:id(.:format)             {:controller=>"classifieds", :action=>"show"}
                        PUT    /classifieds/:id(.:format)             {:controller=>"classifieds", :action=>"update"}
                        DELETE /classifieds/:id(.:format)             {:controller=>"classifieds", :action=>"destroy"}
                        POST   /user(.:format)                        {:controller=>"users", :action=>"create"}
                        GET    /user/new(.:format)                    {:controller=>"users", :action=>"new"}
                        GET    /user/edit(.:format)                   {:controller=>"users", :action=>"edit"}
                        GET    /user(.:format)                        {:controller=>"users", :action=>"show"}
                        PUT    /user(.:format)                        {:controller=>"users", :action=>"update"}
                        DELETE /user(.:format)                        {:controller=>"users", :action=>"destroy"}
                   root        /(.:format)                            {:controller=>"main", :action=>"index"}
                               /:controller(/:action(/:id(.:format)))
                               /simple_captcha/:action(.:format)      {:controller=>"simple_captcha"}
                 logout        /logout(.:format)                      {:controller=>"users", :action=>"destroy"}
                  login        /login(.:format)                       {:controller=>"users", :action=>"show"}
            adminsearch        /adminsearch(.:format)                 {:controller=>"classifieds", :action=>"adminsearch"}
             mainsearch        /mainsearch(.:format)                  {:controller=>"main", :action=>"mainsearch"}
                               /:permalink_1/categorysearch(.:format) {:controller=>"main", :action=>"categorysearch"}
      contactadvertiser        /contactadvertiser(.:format)           {:controller=>"main", :action=>"contactadvertiser"}
                               /:permalink_1(.:format)                {:controller=>"main", :action=>"city"}
                   edit        /edit(.:format)                        {:controller=>"cities", :action=>"edit"}
                               /activate/:activation_code(.:format)   {:controller=>"main", :action=>"activate"}
                               /edit/:activation_code(.:format)       {:controller=>"classifieds", :action=>"edit"}
                               /update/:activation_code(.:format)     {:controller=>"classifieds", :action=>"update"}
                               /delete/:activation_code(.:format)     {:controller=>"classifieds", :action=>"destroy"} classifieds_multidelete        /classifieds/multidelete(.:format)     {:controller=>"classifieds", :action=>"delete_multiple"}
                               /:permalink_1/:permalink_2(.:format)   {:controller=>"main", :action=>"category"}
                               /:permalink_1/:permalink_2/:permalink_3(.:format) {:controller=>"classifieds", :action=>"show"}
         simple_captcha        /simple_captcha/:id(.:format)          {:controller=>"simple_captcha", :action=>"show"}
2

2 Answers

0
votes

You want to do:

<%= link_to "Edit", edit_classified_path(:activation_code => classified)%> 

or edit your routes.rb to:

match '/edit/:id', :controller => 'classifieds', :action => 'edit'
0
votes

Your routes are very redundant and contradictory. First, try getting rid of the catch-all route:

match ':controller(/:action(/:id(.:format)))'

as it should not be used if you're using RESTful routes. If that doesn't help, let me know and I'll update my answer accordingly.

Further, all of your match routes are incorrect. They should follow the pattern:

match '/my_controller/:id' => 'my_controller#action'