How to add external resource file to rails 4 project?

I have external files css, javascriptand Imagesin a separate project, and you want to include in my new project rails. Here is my folder structure:

external-assets/js/ <Files>
external-assets/js/plugin/<Files>
external-assets/css/<Files>
external-assets/css/plugins/<Files>
external-assets/images/<some Folders>/<Files>
external-assets/images/<Files>

So, I copied the folder external-assets/jsto app/assets/javascriptand for csscopied external-assets/cssto app/assets/stylesheets.

and replace <link rel="icon" href="external-assets/css/plugins/bootstrap.min.css">with <%= stylesheet_link_tag "/plugins/bootstrap.min.css" %>in my file html.erb. I did the same for other files cssand js. When I start the server, I got this error:

Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( style.css )` to `config/initializers/assets.rb` and restart your server

After searching in SO postlike: The object is filtered and will not be serviced: add `config.assets.precompile and the object is Filtered and will not be serviced . I need to list all of my files jsand csson config.assets.precompile.

Questions

1) Do I need to mention all the files js, cssand Images? I know the reason, but I have a lot of resource files.

2) What if I put them in a folder public? Is this a good approach?

3) For css, javascript_link_tagfor js exists stylesheet_link_tag. What about images?

+4
source share
3 answers

js, css images? , .

.

require, , "require" application...

#app/assets/javascripts/application.js
//= require x

? , ... (application), .

2) , ? ?

.

minified public/assets .

3) stylesheet_link_tag css, javascript_link_tag js. ?

image_tag


, "" .

(, Google JQuery repo), javascript_include_tag stylesheet_link_tag :

<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" %>

:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

, , #app/views/layouts/application ( ).

-

Rails Assets

....

"" , .

, , .

( ), Rails Assets

enter image description here

gem ( source https://rails-assets.org Gemfil), .

Bower - . :

#Gemfile
gem "rails-assets-jquery.easing"

#app/assets/javascripts/application.js
//= require jquery.easing

JS/CSS, , require.

, , , bundler.

, , .

+2
  • , html <script>, <link>, ≤img> . Sprockets, , .

  • application.css/application.js , . custom.css/custom.js, :

    Rails.application.config.assets.precompile += %w( custom.css custom.js )
    
+1

_ tree .js application.css? , .

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory in the output file. These paths should be relative to the manifest file. You can also use the require_directory directive, which includes all JavaScript files in only the specified directory without recursion.

Check out this guide.

Hope this helps. :)

0
source

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


All Articles