Rails 3 Resources and CSS Relative URLs

I have several CSS files that reference images using relative paths such as url( "../img/my_image.jpg" ).

Everything works in development, but in the productionenvironment, since all CSS files are packed into one file and the structure is lost, as well as the paths of relatives are lost, and the images were not found.

Details of my structure

I have an asset structure like this:

/app
  /assets
    /plugins
      /my_plugin
        /img
          my_image.jpg
        /css
          my_css.css

( /my_plugincan be any plug-in, which is a group of files css, jsand images, like Twitter Bootstrap, any other)

As /app/assets/plugins/my_plugin/my_css.cssI have something like:

background-image: url("../img/my_image.jpg");

In /app/assets/stylesheets/application.css:

*= require css/my_css.css

And finally, in headmy file html:

<%= stylesheet_link_tag "application" %>

What should I do to fix the problem?

Update

- , README .

+5
2

CSS. CSS : application.css *= require_tree .

app/assets/images. , , . 2.2 " ". :

CSS ERb:

 url(<%= asset_path 'image.png' %>)

CSS Sass:

 image-url("rails.png")

.

UPD

, . / . plugins public ( <APP_ROOT>/public/plugins/).

application.css:

*= require bootstrap/css/bootstrap

application.html.erb:

  <%= stylesheet_link_tag    "/plugins/bootstrap/css/bootstrap.min.css", :media => "all" %>
  <%= javascript_include_tag "/plugins/bootstrap/js/bootstrap.min.js" %>

, public/plugins/bootstrap.

UPD 2

, Rails precompile :

# /config/environments/production.rb
config.assets.precompile += %w( bootstrap/css/bootstrap.css )
+7

/app/vendor/assets/plugins, , , , , , .

:

/app
  /vendor
    /assets
      /plugins
        /my_plugin
          /img
            my_image.jpg
          /css
            my_css.css

css stylesheet_link_tag :

<%= stylesheet_link_tag "my_plugin/css/my_css", :media => "all" %>

, Rails , my_css.css , rake assets:precompile.

, Rails :

# /config/environments/production.rb
config.assets.precompile += %w( my_plugin/css/my_css.css )

rake assets:precompile css, production URL-.

diff,

+2

All Articles