Where do you put CSS files in a rails app directory?

前端 未结 6 1112
甜味超标
甜味超标 2021-01-17 08:21

Where should i create a folder to house my CSS files within my rails app directory??

相关标签:
6条回答
  • 2021-01-17 08:32

    stylesheet_link_tag takes arrays of stylesheets as well as a string.

    For example:

    = stylesheet_link_tag %w[ screen print ]
    

    There are some great examples of using the stylesheet_link_tag helper at APIDock.

    0 讨论(0)
  • 2021-01-17 08:37

    For Rails 3.1+ apps, you should use the asset pipeline. Place stylesheets in app/assets/stylesheets/ if they are specific to your application. You can also put them at vendor/assets/stylesheets/ if they are external (say if they are stylesheets for a javascript plugin.)

    After that, you will include stylesheets using the app/assets/stylesheets/application.css if it is included in your layout file (see other answers for how to do this.)

    0 讨论(0)
  • 2021-01-17 08:38

    for Rails 2.x : public/stylesheets

    0 讨论(0)
  • 2021-01-17 08:57

    /app is for programmatic content (your models, views, controllers, layouts, partials, etc). /public is for your static content (html, images, stylesheets, javascripts, etc)

    so the correct place for your stylesheets would be /public/stylesheets. If you follow this convention, you can use the stylesheet_link_tag helper, so if you put style.css into /public/stylesheets, then

    <%= stylesheet_link_tag "style" %>
    

    will get rendered as

    <link href="/stylesheets/style.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
    
    0 讨论(0)
  • 2021-01-17 08:58

    For Rails 4:

    1) Add your .css file in app/assets/stylesheets

    2) In your view file <%= stylesheet_link_tag 'uploaded_file_name' %>

    0 讨论(0)
  • 2021-01-17 08:58

    put it in public/stylesheets

    then use

    <%= stylesheet_link_tag "style_sheet_file_name" %>
    

    in your

    0 讨论(0)
提交回复
热议问题