當我嘗試創建新的數據庫條目或更新當前數據時,出現路由錯誤。Rails 4名稱空間
錯誤:沒有路由匹配[POST] 「/酒吧」
的routes.rb:
resources :people, except: [:show] do
resources :pubs, except: [:create, :new, :edit, :destroy]
end
resources :articles
resources :pubs, except: [:create, :new, :edit, :destroy]
namespace :sekret do
resources :people do
resources :pubs
end
end
sekret/pubs_controller
class Sekret::PubsController < SekretController
def index
@pubs = Pub.all
end
def show
@pub = Pub.find(params[:id])
end
def new
@person = Person.find(params[:person_id])
@pub = @person.pubs.new
end
def create
@pub = Pub.new(pub_params)
if @pub.save
flash[:notice] = "Article created successfully!"
redirect_to sekret_person_pub_path(@pub)
else
render :new, status: :unprocessable_entity
end
end
def edit
@pub = Pub.find(params[:id])
end
def update
@pub = Pub.find(params[:id])
if @pub.update(pub_params)
redirect_to sekret_person_pub_path(@pub)
else
render :edit, status: :unprocessable_entity
end
end
def destroy
pub = Pub.find(params[:id])
pub.destroy
redirect_to sekret_people_path
end
private
def pub_params
params.require(:pub).permit(
:pubmed_id, :journal, :pages, :date, :type, :link, :authors,
:title, :notes, :auth_id, :person_id)
end
end
通過所有這些設置的打算後,當,我允許非命名空間的pubs解析編輯,更新等,更新過程順利完成。一旦我將這些函數限制在受密碼保護的命名空間中,我就會收到路由錯誤。通過路線解析後,我可以看到sekret_person_pub_path在那裏列出。我想我在某個地方失去了一些東西。
耙路線:
pubs#index
pub GET /pubs/:id(.:format) pubs#show
PATCH /pubs/:id(.:format) pubs#update
PUT /pubs/:id(.:format) pubs#update
sekret_person_pubs GET /sekret/people/:person_id/pubs(.:format) sekret/pubs#index
POST /sekret/people/:person_id/pubs(.:format) sekret/pubs#create
new_sekret_person_pub GET /sekret/people/:person_id/pubs/new(.:format) sekret/pubs#new
edit_sekret_person_pub GET /sekret/people/:person_id/pubs/:id/edit(.:format) sekret/pubs#edit
sekret_person_pub GET /sekret/people/:person_id/pubs/:id(.:format) sekret/pubs#show
PATCH /sekret/people/:person_id/pubs/:id(.:format) sekret/pubs#update
PUT /sekret/people/:person_id/pubs/:id(.:format) sekret/pubs#update
DELETE /sekret/people/:person_id/pubs/:id(.:format) sekret/pubs#destroy
sekret_people GET /sekret/people(.:format)
你什麼時候看到'''耙路線'''? – SacWebDeveloper
將路線添加到原始帖子。由於我對所有這些都是新手,如果路線是:/sekret/people/:person_id/pubs/:id(.:format)我是否必須找到一種方法將person_id和:id放在那裏或將會它根據它正在更新的頁面生成? – lostrennie