使用Ruby on Rails进行命名空间布局渲染

时间:2023-01-07 20:42:07

I have an application with a namespace 'admin'.

我有一个名为'admin'命名空间的应用程序。

I created my views on a folder called admin->highligths. And want that, when my views are rendered, it gets the layout from 'admin/layouts/application'.

我在名为admin-> highligths的文件夹上创建了我的视图。并且想要,当我的视图被渲染时,它从'admin / layouts / application'获得布局。

But, when I render my pages, it is getting from the base layout folder.

但是,当我渲染我的页面时,它是从基本布局文件夹中获取的。

  Rendered admin/highlights/index.html.erb within layouts/application (0.7ms)

My routes are like this:

我的路线是这样的:

namespace :admin do root 'pages#show', id: 'dashboard'

命名空间:admin执行root'pages#show',id:'dashboard'

resources :events
resources :invitees do
  collection do
    get 'import_invitees/:year' => 'invitees#import_invitees', as: :import_invitees
  end
end
resources :highlights
resources :pages
resources :speakers
resources :sponsors
resources :users
resources :years do
  resources :events do
    resources :photos
  end
end

end

结束

All my other views (sponsours, invitees, etc...) are getting the template from 'admin/layouts/application' , but highlight (the new one I created)only render with the 'layouts/application'.

我的所有其他观点(赞助商,被邀请者等)都从'admin / layouts / application'获取模板,但突出显示(我创建的新模板)仅使用'layouts / application'进行渲染。

What Im missing here?

我在这里失踪了什么?

1 个解决方案

#1


1  

There are multiple possibilites. In the dark, I would assume that your other Controllers inherit from an AdminController (or similar), that defines the layout, but the "new one" does not.

有多种可能性。在黑暗中,我会假设你的其他控制器继承了一个AdminController(或类似的),它定义了布局,但“new one”却没有。

For reference about how to make controllers use certain layouts by defaults: http://guides.rubyonrails.org/layouts_and_rendering.html

有关如何使控制器默认使用某些布局的参考:http://guides.rubyonrails.org/layouts_and_rendering.html

#1


1  

There are multiple possibilites. In the dark, I would assume that your other Controllers inherit from an AdminController (or similar), that defines the layout, but the "new one" does not.

有多种可能性。在黑暗中,我会假设你的其他控制器继承了一个AdminController(或类似的),它定义了布局,但“new one”却没有。

For reference about how to make controllers use certain layouts by defaults: http://guides.rubyonrails.org/layouts_and_rendering.html

有关如何使控制器默认使用某些布局的参考:http://guides.rubyonrails.org/layouts_and_rendering.html