开发者

Rails override controller layout in gem

开发者 https://www.devze.com 2023-02-21 18:48 出处:网络
I am using a gem that adds an engine to my Rails app with routes that all render snippets of html using the default application layout.I want the controller in this gem to use a different layout.Is th

I am using a gem that adds an engine to my Rails app with routes that all render snippets of html using the default application layout. I want the controller in this gem to use a different layout. Is there a way I can add code to an initializer that will dynamically cause a controller in a gem to always use a layout. E.g. can I 开发者_开发百科throw something like the following code (which isn't working) in an initializer assuming the full definition of SampleController is defined in the gem I am using?

class SampleController
  layout 'my_layout'
end

I know you can call class_eval or instance_eval for class and instance methods but how to override this type of initialization code?


If you create a 'sample.html.haml' (or whichever templating language) in your layouts directory, it will be used instead of application.html for SampleController.

http://guides.rubyonrails.org/layouts_and_rendering.html#finding-layouts

0

精彩评论

暂无评论...
验证码 换一张
取 消