2011-10-05 10 views

答えて

13

は、すべてあなたのスタイルシートはapplication.cssにマージされます。

あなたが持つ特定のスタイルシートを必要とすることができます

%head 
= yield :head 

をし、あなたのページに:

*= require main 

そうでない場合は、あなたのレイアウトでは、次のように記述

= content_for :head do 
= stylesheet_link_tag 'stylesheet' 
+0

%headとyield:headビットは何をしますか? –

+0

In Haml: ヘッド =ヘッド: タグをHTMLで生成し、別のページのコードをyield – damienbrz

3

も参照してください:
http://guides.rubyonrails.org/layouts_and_rendering.html

(セクション2.2.14 'ファインディングレイアウト' を参照)

あなたが別のコントローラに異なるレイアウトを持つことができます!

app/views/layoutsの下でapplication.hamlとadmin.haml があり、app/controllersの下にadmin_controller.rbがあります。

Railsはコントローラと同じ名前のレイアウトを見つけようとします。

また、この動作をオーバーライドして、この新しいレイアウト/スタイルシートを、例えば:使用する

class ItemsController < ApplicationController 
    layout "admin" 
    #... 
end 

あなたはその後、アプリの下admin.scssファイルを作成したレイアウトを指定することができます!それは、* = require_treeによるものだ

/* 
* This is a manifest file that'll automatically include all the stylesheets available in this directory 
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 
* the top of the compiled file, but it's generally better to create a new file per style scope. 
*= require_self 
*= require_tree . 
*/ 

:ようなあなたのapplication.cssが見える場合のRails 3.1では

+0

+1同じ古いリンクをダンプするのではなく、実際にどのセクションを見るかを指定します。ありがとう。 – ahnbizcad

+0

ありがとう。はい、それはちょっとしたページです、彼らはセクション番号を変更しました – Tilo

10

は私を追加してみましょう私のために働いた解決策。前の回答で述べたように

あなたはapplication.cssファイルから

*= require_tree . 

ステートメントを削除したい場合があります。

私は、アプリケーション全体で共有スタイルのための

*= require_self 

声明を保ちました。

はその後、私のapplication.htmlファイルに私が唯一application.cssとビューのcontroller.controller_name.cssスタイルシートを含めるために、次の文を使用していました。

= stylesheet_link_tag "application", controller.controller_name 
= javascript_include_tag "application", controller.controller_name 

JavaScriptファイルについても同じように動作します。

関連する問題