Alex Freshmann
Alex Freshmann

Reputation: 481

'show' route matched instead 'new'

rails 3.1

rake routes for admin/sections_contoller

trigger_admin_section GET    /admin/sections/:id/trigger(.:format)    {:action=>"trigger", :controller=>"admin/sections"}
       admin_sections GET    /admin/sections(.:format)                {:action=>"index", :controller=>"admin/sections"}
                      POST   /admin/sections(.:format)                {:action=>"create", :controller=>"admin/sections"}
    new_admin_section GET    /admin/sections/new(.:format)            {:action=>"new", :controller=>"admin/sections"}
   edit_admin_section GET    /admin/sections/:id/edit(.:format)       {:action=>"edit", :controller=>"admin/sections"}
        admin_section GET    /admin/sections/:id(.:format)            {:action=>"show", :controller=>"admin/sections"}
                      PUT    /admin/sections/:id(.:format)            {:action=>"update", :controller=>"admin/sections"}
                      DELETE /admin/sections/:id(.:format)            {:action=>"destroy", :controller=>"admin/sections"}

routes.rb

namespace :admin do
  resources :sections do
    resources :items
    resources :parameters
    get :trigger, :on => :member
  end
...
end

view

<%= link_to "Add a section", new_admin_section_path, :class=>'add-btn' %>

generated link

http://localhost:3000/admin/sections/new

result

No route matches {:action=>"show", :controller=>"admin/sections", 
                  :id=>#<Section id: nil, ..., meta_description: nil}

strange bug or my mistake. other controllers has similar routes and all works fine. for ex.:

 <%= link_to 'Add a group', new_admin_group_path, :class=>'add-btn' %>

works GREAT!

please, help or i'll kill myself someday

upd1 same problem on heroku with this app.

upd2 join github issue: https://github.com/rails/rails/issues/4704

Upvotes: 2

Views: 806

Answers (2)

Alex Freshmann
Alex Freshmann

Reputation: 481

i found the answer.

once i put this string in view 'admin/section/_form'

<%= link_to 'delete', admin_section_path(@section), :method => :delete, :confirm => "Sure?" %>

i used this form for creating and editing. so combination of new object and deleting link for it caused the bug. i used debugger for analysis.

Upvotes: 1

michel
michel

Reputation: 110

Look at your "create" method in sections_controller.

I guess your section is correctly created but it redirect to "show" action. And "show" view may not exist.

Have you checked your database ? Is the section saved ?

Upvotes: 0

Related Questions