0

/about作成した CMS エンジンがあり、それをメイン サイトにリンクしました。現在、代わりににルーティングしようとして/1います。これは、CMS エンジン ページ コントローラにマップされ、アクションを表示します。

example pages setup
id | name    | title      | body
1  | about   | About Us   | this is the about page
2  | contact | Contact Us | this is the contact page

/1またはに正常にルーティングされます/2

routes.rbこれは、cmsエンジンをロードするメインアプリケーションの私のものです

  mount Cms::Engine, :at => '/cms', :as =>'cms'
  mount Blog::Engine, :at => '/blog', :as => 'blog'

  # route to cms pages
  match ":id", :to => 'cms/pages#show', :via => [:get, :post]

CMS ページ コントローラーの表示アクションは次のとおりです。

# GET /pages/1  or GET /pages/name
def show
  begin
     @page = Page.find_by_name(params[:id]) 
     @page ||= Page.find(params[:id]) 
  rescue
    redirect_to "/404.html"
  end
end

何を試しても、ページを/nameso/aboutまたはにルーティングすることはできません/contact。代わりに、または というエラーが表示されますが、Couldn't find Cms::Page with id=aboutまたはCouldn't find Cms::Page with id=contactに移動すると/1/2ページがレンダリングされます。

私のレーキルートは次のとおりです。

Prefix Verb     URI Pattern    Controller#Action
 cms          /cms           Cms::Engine
blog          /blog          Blog::Engine
     GET|POST /:id(.:format) cms/pages#show

Routes for Cms::Engine:
    pages GET    /pages(.:format)          cms/pages#index
          POST   /pages(.:format)          cms/pages#create
 new_page GET    /pages/new(.:format)      cms/pages#new
edit_page GET    /pages/:id/edit(.:format) cms/pages#edit
     page GET    /pages/:id(.:format)      cms/pages#show
          PATCH  /pages/:id(.:format)      cms/pages#update
          PUT    /pages/:id(.:format)      cms/pages#update
          DELETE /pages/:id(.:format)      cms/pages#destroy
     root GET    /                         cms/login#index

Routes for Blog::Engine:
root GET / blog/index#index
4

1 に答える 1