モデルの場所、カテゴリ、サブカテゴリ、および製品のために、自分のアプリのルートをネストしました。私は私のページモデルとルートパスのためにしたように、path: ' ' to each route
を追加してディレクトリパスを削除しました。このアプリはリンクを編集して削除する以外は完全に機能します。私が受け取ったエラーはcan't find record with friendly id: "edit"
Rails 5ディレクトリ名を削除した後の編集と破棄のネストされたルーティングエラー
です。私は大部分が4つの深い入れ子に同意しないことを知っていますが、非常に具体的な理由で行われますので、検索エンジンがインデックスとランク付けする固定URLパターンを取得します。ディレクトリを削除して編集を維持するにはどうしたらいいですか?
Rails.application.routes.draw do
mount StripeEvent::Engine, at: '/webhooks/stripe'
devise_for :users
resources :users
resources :locations do
resources :categories, path: '' do
resources :subcategories, path: '' do
resources :products, path: ''
end
end
end
root 'pages#show', defaults: { id: 'my-little-carnival' } # shows home page as default from pages controller
get '/pages/list' => 'pages#index' # sets pages index page before setting path to ''
resources :pages, path: ''
end
スタックトレースのトップ
Started GET "/locations" for 127.0.0.1 at 2017-11-28 20:41:37 -0800
Processing by LocationsController#index as HTML
Rendering locations/index.html.erb within layouts/application
Location Load (0.3ms) SELECT "locations".* FROM "locations"
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Rendered locations/index.html.erb within layouts/application (4.2ms)
Rendered layouts/_main-menu.html.erb (0.2ms)
Rendered layouts/_header.html.erb (3.5ms)
Rendered layouts/_standard-page.html.erb (0.3ms)
Rendered layouts/_footer.html.erb (0.6ms)
Completed 200 OK in 74ms (Views: 71.9ms | ActiveRecord: 0.7ms)
Started GET "/locations/san-diego/edit" for 127.0.0.1 at 2017-11-28 20:41:39 -0800
Processing by SubcategoriesController#index as HTML
Parameters: {"location_id"=>"san-diego", "category_id"=>"edit"}
Location Load (0.3ms) SELECT "locations".* FROM "locations" WHERE "locations"."slug" = $1 LIMIT $2 [["slug", "san-diego"], ["LIMIT", 1]]
Category Load (0.4ms) SELECT "categories".* FROM "categories" WHERE "categories"."slug" = $1 LIMIT $2 [["slug", "edit"], ["LIMIT", 1]]
Completed 404 Not Found in 3ms (ActiveRecord: 0.7ms)
パスは上から下に処理されます。私はあなたの問題は、どのように物事を整理し、あなたのパスが予期しない方法で一致していることを考えれば推測しています。しかし、より完全なスタックトレース(最初のいくつかの行)がなくても、良い感じを得るのは難しいです。 – jvillian
@jvillian質問にスタックトレースの先頭部分を追加しました。パスが 'path: '''に設定されているように見え、それはスキップしてその下のコントローラーを使用しています。 –
大変申し訳ありませんが、それはトップですか?私は127.0.0.1で '開始GET"/blah/blah/blah "となるだろうと考えていました。私はまだRails 4に入っています。多分今は違うかもしれません。 – jvillian