简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM