Rails3 asset pipeline and file conflicts

I am updating an existing rails 2 application for rails 3, and have some problems understanding the asset pipeline. I read the guide , and as I understand it, files in any of the following directories will be allowed for / assets:

  • application / assets
  • Library / Assets
  • supplier / assets

and you can access them with helpers ... i.e.

image_tag('logo.png') 

But I do not understand how conflicts are handled? For example, what if there are the following files:

  • application / assets / images / logo.png
  • Library / assets / images / logo.png

If I go to myapp.com/assets/images/logo.png, which file will be returned? I can check for conflicts manually in my application, but this becomes a pain point when using gems that rely on an asset pipeline.

+6
source share
2 answers

Based on what I found, you cannot duplicate files since the rails will simply return the first one found.

This seems like a design flaw, as a gem cannot contain spaces in its own resources.

+2
source

Why not use index manifest and organize your app/assets into decoupled modules? Then you can link to a specific image, image_tag('admin/logo.png') , and get your own UI code base organized in a more meaningful way for free. You could even promote a complex component, such as a one-page application, into its own module and reuse it from different parts of the application.

Let's say the application is composed of three modules: the public side, the admin user interface, and, for example, CRM, so that your agents monitor the sales process in your company:

 app/assets/ β”œβ”€β”€ coffeescripts β”‚  β”œβ”€β”€ admin β”‚  β”‚  β”œβ”€β”€ components β”‚  β”‚  β”œβ”€β”€ index.coffee β”‚  β”‚  └── initializers β”‚  β”œβ”€β”€ application β”‚  β”‚  β”œβ”€β”€ components β”‚  β”‚  β”œβ”€β”€ index.sass β”‚  β”‚  └── initializers β”‚  └── crm β”‚  β”œβ”€β”€ components β”‚  β”œβ”€β”€ index.sass β”‚  └── initializers β”œβ”€β”€ images β”‚  β”œβ”€β”€ admin β”‚  β”œβ”€β”€ application β”‚  └── crm └── stylesheets β”œβ”€β”€ admin β”‚  β”œβ”€β”€ components β”‚  └── index.sass β”œβ”€β”€ application β”‚  β”œβ”€β”€ components β”‚  └── index.sass └── crm β”œβ”€β”€ components └── index.sass 21 directories, 6 files 

Remember to update your application.rb so that they are precompiled:

  config.assets.precompile = %w(admin.js application.js crm.js admin.css application.css crm.css) 
0
source

Source: https://habr.com/ru/post/908319/


All Articles