set a layout for certain actions?

前端 未结 2 1237
说谎
说谎 2021-02-02 13:43

My app/views/layouts folder looks like this:

application.html.erb
user_sessions.html.erb
errors.html.erb

These work fine and i have no problems

2条回答
  •  离开以前
    2021-02-02 14:28

    If you want to use multiple layout in a controller, use the code below: ( action_name is a pre-defined variable that you could use directly in Rails)

    class OrdersController < BaseController
      layout :determine_layout
    
    private
      def determine_layout
        %w(new).include?(action_name) ? "some_layout" : "public"
      end
    end
    

    see: https://stackoverflow.com/a/5525014/445908

提交回复
热议问题