2014-02-09 42 views

回答

0

在主應用程序的佈局文件(通常是:/app/views/layouts/application.whatever)

定義頭元件內2個獨立的JS文件。

javascript_include_tag 'public' 
javascript_include_tag 'admin' 

然後創建您的資產2個獨立的js文件/ JavaScript的文件夾,名爲「公共」和「管理員」,並使用那些你加入JavaScript。

2

結構,你的應用程序,像這樣:

- app 
    - assets 
    - javascripts 
     - admin 
     (all admin-facing js files go here) 
     - public 
     (all public-facing js files go here) 
     admin.js 
     public.js 
    - stylesheets 
     - admin 
     (all admin-facing css files go here) 
     - public 
     (all public-facing css files go here) 
     admin.css 
     public.css 

admin.js

//= require_tree ./admin 

public.js

//= require_tree ./public 

admin.css

/* 
*= require_directory ./admin 
*/ 

public.css

/* 
*= require_directory ./public 
*/ 

app/views/layouts/application.html.erb(或者是你的主要佈局文件):

<!-- Change this: --> 

    <%= stylesheet_link_tag "application", media: "all" %> 
    <%= javascript_include_tag "application" %> 


<!-- To this: --> 

    <%= stylesheet_link_tag "public", media: "all" %> 
    <%= javascript_include_tag "public" %> 

在每一個觀點,即是admin面向,加上這一點,無論是通過一些佈局或手動插入每一個:

<%= stylesheet_link_tag "admin", media: "all" %> 
    <%= javascript_include_tag "admin" %> 

config/environments/production.rb中,加入硫s線在configure區塊內:

config.assets.precompile += %w(public.js admin.js public.css admin.css)