Should frontend and backend be handled by different controllers?

后端 未结 4 403
自闭症患者
自闭症患者 2021-02-01 09:52

In my previous learning projects I always used a single controller, but now I wonder if that is good practice or even always possible.

In all RESTful Rails tutorials the

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 10:22

    Use two current if there are two modules 1] Admin 2] User

    Say

    class BookUserController < ApplicationController
      #Here layout is used will be of layouts/application.html.erb
      #Here all the methods which user can will be present 
    end
    
    
    class BookAdminController < ApplicationController
      layout 'admin'  #here we set the layout is layouts/admin.html.erb 
    
    end
    

    IF Only one page you want to show admin you can use single controller and two methods

    class BookUserController < ApplicationController
      layout 'admin', :only=>['index_admin']
    
      def index_admin
    
    
      end
    
      def index
    
    
    
      end
    
    
    end
    

    OR

    class BookUserController < ApplicationController
      def index_admin
    
        render :action=>'index_admin', :layout => false
      end
    
      def index
    
    
    
      end
    
    
    end
    

提交回复
热议问题