私のコントローラーの 1 つで、ある条件を指定してレイアウトを変更し、それ以外の場合は、親 ApplicationController が使用するデフォルトのレイアウトを維持したいと考えています (最初は「アプリケーション」でしたが、現在は他のいくつかを試しています)。alias_method を使用して「レイアウト」にアクセスしようとしましたが、うまくいかないようです。私のコード:
class SomeController < ApplicationController
alias_method :parent_layout, :layout
layout :some_layout
def some_layout
if some_condition
"new_layout"
else
:parent_layout
end
end
end
これによりエラーが発生します。
ActionController::RoutingError (undefined method `layout' for class `SomeController'):
app/controllers/some_controller.rb:6:in `alias_method'
app/controllers/some_controller.rb:6:in `<class:SomeController>'
app/controllers/some_controller.rb:3:in `<top (required)>'