我的路线有问题。刚注意到一件奇怪的事。我没有:在我的show / edit / ...路由中的id。
这是我的rake.routes输出:
WARNING: Nokogiri was built against LibXML version 2.9.0, but has dynamically loaded 2.9.2
Prefix Verb URI Pattern Controller#Action
new_person_session GET /persons/sign_in(.:format) devise/sessions#new
person_session POST /persons/sign_in(.:format) devise/sessions#create
destroy_person_session DELETE /persons/sign_out(.:format) devise/sessions#destroy
person_password POST /persons/password(.:format) devise/passwords#create
new_person_password GET /persons/password/new(.:format) devise/passwords#new
edit_person_password GET /persons/password/edit(.:format) devise/passwords#edit
PATCH /persons/password(.:format) devise/passwords#update
PUT /persons/password(.:format) devise/passwords#update
supplier_password POST /suppliers/password(.:format) devise/passwords#create
new_supplier_password GET /suppliers/password/new(.:format) devise/passwords#new
edit_supplier_password GET /suppliers/password/edit(.:format) devise/passwords#edit
PATCH /suppliers/password(.:format) devise/passwords#update
PUT /suppliers/password(.:format) devise/passwords#update
facilitator_password POST /facilitators/password(.:format) devise/passwords#create
new_facilitator_password GET /facilitators/password/new(.:format) devise/passwords#new
edit_facilitator_password GET /facilitators/password/edit(.:format) devise/passwords#edit
PATCH /facilitators/password(.:format) devise/passwords#update
PUT /facilitators/password(.:format) devise/passwords#update
customer_password POST /customers/password(.:format) devise/passwords#create
new_customer_password GET /customers/password/new(.:format) devise/passwords#new
edit_customer_password GET /customers/password/edit(.:format) devise/passwords#edit
PATCH /customers/password(.:format) devise/passwords#update
PUT /customers/password(.:format) devise/passwords#update
cancel_customer_registration GET /customers/cancel(.:format) devise/registrations#cancel
customer_registration POST /customers(.:format) devise/registrations#create
new_customer_registration GET /customers/sign_up(.:format) devise/registrations#new
edit_customer_registration GET /customers/edit(.:format) devise/registrations#edit
PATCH /customers(.:format) devise/registrations#update
PUT /customers(.:format) devise/registrations#update
DELETE /customers(.:format) devise/registrations#destroy
home_index GET /home/index(.:format) home#index
root GET / home#index
suppliers_index GET /suppliers/index(.:format) suppliers#index
facilitators_index GET /facilitators/index(.:format) facilitators#index
customers_index GET /customers/index(.:format) customers#index
new_customers GET /customers/new(.:format) customers#new
customers_newCustomer POST /customers/newCustomer(.:format) customers#newCustomer
customers_editCustomer GET /customers/editCustomer(.:format) customers#editCustomer
parties POST /parties(.:format) parties#create
new_parties GET /parties/new(.:format) parties#new
edit_parties GET /parties/edit(.:format) parties#edit
GET /parties(.:format) parties#show
PATCH /parties(.:format) parties#update
PUT /parties(.:format) parties#update
DELETE /parties(.:format) parties#destroy
parties_index GET /parties/index(.:format) parties#index
visitors_new POST /visitors/new(.:format) visitors#new
visitors_create POST /visitors/create(.:format) visitors#create
这是我的routes.rb
:
Rails.application.routes.draw do
# devise_for :people
devise_for :persons, :skip => :registrations
devise_for :suppliers, :facilitators, skip: [:registrations, :sessions]
devise_for :customers, :skip => :sessions
# routes for all users
authenticated :persons do
end
# routes only for customers
authenticated :customers, lambda {|u| u.type == "Customer"} do
end
# routes only for companies
authenticated :facilitators, lambda {|u| u.type == "Facilitator"} do
end
# routes only for suppliers
authenticated :suppliers, lambda {|u| u.type == "Supplier"} do
end
# mde toevoegeingen
get 'home/index'
root to: "home#index"
get 'suppliers/index'
get 'facilitators/index'
get 'customers/index'
resource :customers, :only => :new
match 'customers/newCustomer', to: 'customers#newCustomer', via: :post
match 'customers/editCustomer', to: 'customers#editCustomer', via: :get
resource :parties
get 'parties/index'
match 'visitors/new', to: 'visitors#new', via: :post
match 'visitors/create', to: 'visitors#create', via: :post
end
我的网址显示'。'而不是'id'之前的'/'。这是模型的show
方法的示例网址:
http://localhost:3000/parties.2
奇怪的是,正常的路由工作正常。奇怪,因为点用于定义格式。
现在我需要我正在实施remote: true
行为的格式我遇到了麻烦。
我做错了什么?
对待Martijn
答案 0 :(得分:2)
尝试改变:
resource :parties
要:
resources :parties
答案 1 :(得分:2)
就像Brad Werth在评论中所说的那样。
复数resources
resources :photos
创建
GET /photos Photos index display a list of all photos
GET /photos/new Photos new return an HTML form for creating a new photo
POST /photos Photos create create a new photo
GET /photos/1 Photos show display a specific photo
GET /photos/1/edit Photos edit return an HTML form for editing a photo
PUT /photos/1 Photos update update a specific photo
DELETE /photos/1 Photos destroy delete a specific photo
与Singular Resources
您还可以将RESTful路由应用于您的单例资源 应用。在这种情况下,您使用map.resource而不是 map.resources和路由生成略有不同。对于 例如,
的路由条目
resource :geocoded
GET /geocoder/new Geocoders new return an HTML form for creating the new geocoder
POST /geocoder Geocoders create create the new geocoder
GET /geocoder Geocoders show display the one and only geocoder resource
GET /geocoder/edit Geocoders edit return an HTML form for editing the geocoder
PUT /geocoder Geocoders update update the one and only geocoder resource
DELETE /geocoder Geocoders destroy delete the geocode resource