Using specific layout via the controller

Ruby on Rails, 2015-06-16 23:21:20 UTC

Layout placement is very important for Ruby on Rails application. Without layouts, the application looks bad.

These ways to create layout via the controller; 
1. This is a controller example

class ExampleController < ApplicationController

    layout "my_layout"

    def index
    end

    def sesuatu
    end
end


Above code will be define as a layout for all of method in the controller

2. Layour for specific method

class ContohController < ApplicationController

    layout "my_layout", only: [:index, :new, :create]

    def index
    end

    def another_method
    end

    def new
    end

    def create
    end
end

 

Sumber: http://www.develbook.com/2015/02/using-specific-layout-via-controller.html

 


Share: