normeno
normeno

Reputation: 105

How I can manage different layout in Rails 4?

How I can have a special layout in Ruby On Rails 4? For example, I want to call the show method from the backend and front end. The problem is that I need to identify when to call each layout, for example, when calling the URL domain.com/admin/people/1 I want to call backend layout, but when I call the URL domain.com/people/1, I want to call the layout of the front end.

Upvotes: 1

Views: 131

Answers (1)

Doug
Doug

Reputation: 15553

Create your layout in the layouts directory, ie at layouts/admin.html.erb

Route to separate controllers:

class AdminPeopleController 

   def show
       #do things
      render layout: 'admin'
   end
end

class PeopleController
  def show
       #do things
      render #default
   end
end

And add in your routes file:

namespace :admin do
  resources :people, controller: :admin_people
end

resources :people, controller: :people

Upvotes: 3

Related Questions