Note that there are some explanatory texts on larger screens.

plurals
  1. POresources routing mixup
    text
    copied!<p>I have a mystery in my routes:</p> <pre><code>resources :organizations root :to =&gt; 'users#index' devise_for :users, :controllers =&gt; { :registrations =&gt; 'users/registration', :sessions =&gt; 'users/session', :confirmations =&gt; 'users/confirmation'} </code></pre> <p>Now, if I try to reach <code>/organizations/1</code> it works.</p> <p>If I try <code>/organizations</code> or <code>/organizations/new</code></p> <p>I get the same error for both cases: <code>No route matches {:action=&gt;"show", :controller=&gt;"organizations"}</code></p> <p>which path I never requested. And which path exists btw.</p> <p>Is there anything that can intercept routes and do some hidden redirect in rails (or devise)?</p> <p><strong>UPDATE</strong></p> <p>Here are the routes:</p> <pre><code> organizations GET /organizations(.:format) organizations#index POST /organizations(.:format) organizations#create new_organization GET /organizations/new(.:format) organizations#new edit_organization GET /organizations/:id/edit(.:format) organizations#edit organization GET /organizations/:id(.:format) organizations#show PUT /organizations/:id(.:format) organizations#update DELETE /organizations/:id(.:format) organizations#destroy root / users#index new_user_session GET /users/sign_in(.:format) users/session#new user_session POST /users/sign_in(.:format) users/session#create destroy_user_session DELETE /users/sign_out(.:format) users/session#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PUT /users/password(.:format) devise/passwords#update cancel_user_registration GET /users/cancel(.:format) users/registration#cancel user_registration POST /users(.:format) users/registration#create new_user_registration GET /users/sign_up(.:format) users/registration#new edit_user_registration GET /users/edit(.:format) users/registration#edit PUT /users(.:format) users/registration#update DELETE /users(.:format) users/registration#destroy user_confirmation POST /users/confirmation(.:format) users/confirmation#create new_user_confirmation GET /users/confirmation/new(.:format) users/confirmation#new GET /users/confirmation(.:format) users/confirmation#show user_unlock POST /users/unlock(.:format) devise/unlocks#create new_user_unlock GET /users/unlock/new(.:format) devise/unlocks#new GET /users/unlock(.:format) devise/unlocks#show </code></pre> <p><strong>UPDATE</strong></p> <p>Here are OrganizationsController and ApplicationController:</p> <pre><code>class OrganizationsController &lt; ApplicationController before_filter :authenticate_user! def index new render 'organizations/new' end def new @organization = Organization.new end end </code></pre> <p>and </p> <pre><code>class ApplicationController &lt; ActionController::Base protect_from_forgery def after_sign_in_path_for(resource) accounts_path end rescue_from CanCan::AccessDenied do |exception| flash[:error] = exception.message redirect_to :back end end </code></pre> <p><strong>UPDATE</strong></p> <p>Here is the organization's new.html.erb view</p> <pre><code>&lt;%= semantic_form_for @organization, :url =&gt; organization_path do |f| %&gt; &lt;%= f.inputs do %&gt; &lt;%= f.input :country %&gt; &lt;%= f.input :type, :as =&gt; :select, :label =&gt; t(:g_type), :collection =&gt; [[t(:g_company),"Company"],[t(:g_person),"Person"]] %&gt; &lt;% end %&gt; &lt;%= f.actions %&gt; &lt;% end %&gt; </code></pre> <p><strong>UPDATE</strong></p> <p>I also checked that the routes are well defined and they seem to be:</p> <pre><code>&gt;&gt; r = Rails.application.routes #&lt;ActionDispatch::Routing::RouteSet:0x3dbea00&gt; &gt;&gt; r.recognize_path("/organizations/new") {:action=&gt;"new", :controller=&gt;"organizations"} &gt;&gt; r.recognize_path("/organizations/1") {:action=&gt;"show", :controller=&gt;"organizations", :id=&gt;"1"} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload