2014-09-26 61 views
0

這是我的代碼:如何分離在軌應用視圖

的routes.rb

get '/admin', :to => "admin#index" 
namespace :admin do 
    resources :questionnaires, :users, :campaigns 
end 

admin_controller.rb

class AdminController < ApplicationController 

    def index 
    end 

end 

campaigns_controller.rb

module Admin 
    class CampaignsController < AdminController 
     def index 
     end 

     def new 
     end 

     def create 
     end 

     def show 
     end 

     def edit 
     end 

     def update 
     end 

     def destroy 
     end 
    end 
end 

問卷和用戶控制器與廣告系列完全相同。

當我嘗試進入:

/admin/campaigns 

的觀點是管理員的索引視圖。

文件夾控制器看起來像這樣:

controllers 
| admin 
    | campaigns_controller.b 
    | questionnaires_controller.rb 
    | users_controllers.rb 
    admin_controller.rb 

文件夾視圖看起來像這樣:

views 
| index.html.haml 
| admin 
    | questionnaires 
    | | index.html.haml 
    | users 
    | | index.html.haml 
    | index.html.haml 

如何我能把我的意見爲每個資源?

+0

當你訪問'/管理/ questionnaires'會發生什麼? – Surya 2014-09-26 08:02:46

+0

與'/ admin/campaigns'相同# – Ayoros 2014-09-26 08:06:21

+0

@spuyet刪除此行並嘗試一次'get'/ admin',:to =>「admin#index」' – anusha 2014-09-26 08:15:20

回答

1

嘗試你的路線改成這樣:

namespace :admin do 
    resources :questionnaires, :users, :campaigns 
end 
get '/admin', :to => "admin#index" # this line at bottom 
+0

它的工作原理,謝謝:) – Ayoros 2014-09-26 08:27:05