我有一個Rails窗體來爲商店創建配置文件。起初,我已經處理了路由resources :stores
,一切都很好。但是,我想將我的資源分配給管理範圍和「公共」範圍之間的商店。一旦我這樣做,表單提交停止工作,通過我錯誤'沒有路由匹配[POST]「/管理/存儲」'。我不是爲什麼發生這種情況清楚,因爲我以爲我分了我的資源,適當地...Rails創建映射到錯誤的路由
scope "/admin" do
resources :stores, only: [:index, :edit, :update, :destroy]
end
resources :stores, only: [:new, :create]
這裏是控制器的動作......
,我在發現def new
@store = current_user.stores.new
@store.build_address
@storeType = StoreType.all
end
def create
@store = current_user.stores.new(store_params)
if @store.save
flash[:notice] = "New store created"
redirect_to root_path
else
#ERROR STUFF
end
end
一件事Rails的路由信息是,創建POST操作被集中到與其他所有/管理前綴資源的store_path
stores_path
GET /admin/stores(.:format) stores#index
edit_store_path
GET /admin/stores/:id/edit(.:format) stores#edit
store_path
PATCH /admin/stores/:id(.:format) stores#update
PUT /admin/stores/:id(.:format) stores#update
DELETE /admin/stores/:id(.:format) stores#destroy
POST /stores(.:format) stores#create
new_store_path
GET /stores/new(.:format) stores#new
我不知道我理解爲什麼發生這種情況,任何HEL p將不勝感激。爲什麼當我在'public'路徑中添加:new和:create操作時,表單試圖發佈到管理路徑?
非常感謝。
表單是否使用'form_for(@store)'? – max
我不確定我是否理解;你問爲什麼'create'的'store_path'被列在另一個'store_path' HTTP方法下面?我的意思是,這個URL是正確的,它是一個'store_path',並且一切似乎都是正確的。 –
這不是發佈到管理路線,它*顯示*你將發佈的路線。 –