2015-07-12 21 views
2

在我的Rails應用程序中,我有一個控制器「home」和另一個「admin」。從家庭控制器的索引行爲,試圖呈現控制器的索引行爲。在管理控制器中,我指定了要使用的佈局,即「user_layout」,而且家庭控制器正在使用默認的應用程序佈局。 以下是家居控制器如果控制器的動作是從其他控制器調用的,則不會呈現指定的佈局

class HomeController < ApplicationController 

    def index 
    if user_signed_in? 

     @user = User.where(id: current_user.id) 
     @user.each do |user| 
     @allowed_user = user.allow 
     end 

     @org = Organization.where(user_id: current_user.id) 
     #render :template => 'organizations/show' 
     @org.each do |org| 
     session[:current_organization_id] = org.id 
     end 
     respond_to do |format| 
      format.html { render 'admin/index' } 
      format.json { render json:@org} 
     end 
    end 
    end 
end 

管理控制器

class AdminController < ApplicationController 

    before_filter :authenticate_user! 
    layout "user_layout" 
    def index 
    @org = Organization.where(user_id: current_user.id) 
    @user = User.where(id: current_user.id) 
     @user.each do |user| 
     @allowed_user = user.allow 
     end 
    end 
end 

然而,如果不是應用user_layout管理控制器的索引動作是在訪問一些其他控制器的一些其他動作後調用,但而不是從家庭控制器調用時。

回答

1

呈現視圖donot去控制器,所以它不會去管理控制器,並檢查它應該呈現哪個佈局。你必須在家庭控制器中指定它。

請試試這個。

format.html { render "admin/index", layout: "user_layout" } 

在您的響應塊爲索引行動,家庭控制器。

相關問題