我的路线有一个谜团:
resources :organizations
root :to => 'users#index'
devise_for :users, :controllers => { :registrations => 'users/registration', :sessions => 'users/session', :confirmations => 'users/confirmation'}
现在,如果我尝试达到/organizations/1
它的工作原理。
如果我尝试/organizations
或/organizations/new
对于这两种情况,我都会遇到相同的错误:No route matches {:action=>"show", :controller=>"organizations"}
我从未请求过哪条路径。顺便说一句,存在哪条路径。
有什么东西可以拦截路线并在rails(或设计)中进行一些隐藏的重定向吗?
更新
以下是路线:
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
更新
下面是 OrganizationsController 和 ApplicationController:
class OrganizationsController < ApplicationController
before_filter :authenticate_user!
def index
new
render 'organizations/new'
end
def new
@organization = Organization.new
end
end
和
class ApplicationController < 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
更新
这是该组织的 new.html.erb 视图
<%= semantic_form_for @organization, :url => organization_path do |f| %>
<%= f.inputs do %>
<%= f.input :country %>
<%= f.input :type, :as => :select, :label => t(:g_type), :collection => [[t(:g_company),"Company"],[t(:g_person),"Person"]] %>
<% end %>
<%= f.actions %>
<% end %>
更新
我还检查了路线是否定义明确,它们似乎是:
>> r = Rails.application.routes
#<ActionDispatch::Routing::RouteSet:0x3dbea00>
>> r.recognize_path("/organizations/new")
{:action=>"new", :controller=>"organizations"}
>> r.recognize_path("/organizations/1")
{:action=>"show", :controller=>"organizations", :id=>"1"}