Rails override controller layout in gem
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
精彩评论