Images in vendor directory not precompiling - assets

I am using the DataTables library in my Rails 4.2.1 application. I have manually included all of the assets that are required including 1 js file, 1 css file, and 3 images. The js and css are properly precompiling but the images are not.
Currently the three images are located in vendor/assets/images/<name>.png. They are not precompiling (which after some research is intentional in rails 4.0+) and after attempting all of the fixes I could find on SO I still cannot get these images properly loaded by the asset pipeline. I have tried the following fixes to no avail.
Attempted fixes
Move images to app/assets/images
Add config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) to config/application.rb
Add config.assets.paths << Rails.root.join("vendor", "assets", "images") to config/application.rb
Errors
The error messages thrown by DataTables js are the following:
GET http://localhost:3000/vendor/assets/images/sort_both.png 404 (Not Found)
GET http://localhost:3000/vendor/assets/images/sort_asc.png 404 (Not Found)

Related

Migration odoo, Style error Could not get content

I upgraded the database to Odoo 15 but I still got this error:
Style error
The style compilation failed, see the error below. Your recent actions may be the cause, please try reverting the changes you made.
Could not get content for /web/static/src/scss/webclient.scss defined in bundle 'web.assets_backend'.
and the log of browser:
Could not get content for /web_gantt_native/static/src/js/gantt_item_sorted.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:27116:9
Could not get content for /web_gantt_native/static/src/js/gantt_item.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:27119:9
Could not get content for /knowsystem/static/src/js/knowsystem_action_manager.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28037:9
Could not get content for /knowsystem/static/src/js/knowsystem_readonly_formcontroller.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28040:9
Could not get content for /knowsystem/static/src/js/knowsystem_readonly_formview.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28043:9
Could not get content for /knowsystem/static/src/js/sidebar.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28046:9
Could not get content for /web_notify/static/src/js/web_client.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28980:9
Could not get content for /web_notify/static/src/js/widgets/notification.js defined in bundle 'web.assets_backend'. web.assets_backend.min.js:28983:9
I already looked for the files but didn't find them in the addons src files also removed the ir_attachemnts for all js !
Any one got this error before and found a solution ?
Cause of the issue
This issue happens when static files no longer exist in a newer version of an app. After the migration is performed the assets bundles still expect to find them.
Solution
You can just delete those asset objects from shell for example(and do the same with the rest):
env['ir.asset'].search([('path', '=', '/web_gantt_native/static/src/js/gantt_item_sorted.js')]).unlink()
env.cr.commit()
If the record does not exist on the database add the static file as explained in the alternative solution.
Alternative Solution
Temporarily create those files. For example in your case create an empty file /web_gantt_native/static/src/js/gantt_item_sorted.js and include(Odoo Assets documentation) it in web.assets_backend. Once that is done, the issue should be gone and the database should run normal.
The answer provided looks fine, I just want to add that you can using the developer mode use the "regenerate asset bundle" feature that will help you with those kinds of assets issues.

Rails Production Single JS File Isn't Precompiled?

So I have a file jquery.tmpl.min.js sitting under app/assets/javascripts/ and for whatever reason it's not being found in my production server. After runnings rake assets:precompile it completes without any errors whatsoever. All my other javascript assets get compiled properly and sent to the browser. I don't have any issues on my development server finding this JS file.
I have the following lines in my production.rb file:
config.serve_static_assets = true
config.assets.compile = true
config.assets.precompile += %w( *.js *.css )
Error message:
ActionController::RoutingError (No route matches [GET] "/assets/jquery.tmpl.min.js"):
Edit
According to this issue: https://github.com/rails/rails/issues/3596
Using the javascript_include_tag with something like 'jquery.ba-url.min' wont append the .js extension. Originally I had that but have since changed it to include the .js extension. Still no dice however.
Edit 2
I tried adding //= require jquery.tmpl.min.js to my application.js but now when I attempt to precompile my assets it says it can't find the file.
Edit 3
Tried adding //= require_tree and still it isn't found. This is driving me nuts!
Ok, I found the answer. It turns out Edit 2 was the fix that I was looking for. Problem was that I made the edit on development and commited to my production server using github. However I forgot to add the renamed file to the commit so all my commit ended up doing was deleting the file on the production server.

Rails asset pipeline can't find one certain image

I have a certain image called ui-icons_ffffff_256x240.png. In production it can be found, among other places, in public/assets/images/ui-icons_ffffff_256x240.png.
When I try to view this image in production, I get the following error:
ActionController::RoutingError (No route matches [GET] "/assets/images/ui-icons_ffffff_256x240.png"):
I find this extremely odd since the image most certainly is there:
$ find . -name ui-icons_ffffff_256x240.png
./vendor/assets/stylesheets/jquery-ui/images/ui-icons_ffffff_256x240.png
./public/assets/jquery-ui/images/ui-icons_ffffff_256x240.png
./public/assets/images/ui-icons_ffffff_256x240.png
All the other images in my app work fine and have been forever. I recently upgraded my version of jQuery UI, though, and this one particular image doesn't want to work. (I think it's the only jQuery UI image I'm actually using.)
I'm on Rails 3.2.1. What could be the issue?
Your js plugin requests the image with invalid asset url.
The asset image can be accessed by
/assets/ui-icons_ffffff_256x240.png
But the requested url is
/assets/images/ui-icons_ffffff_256x240.png
So in your javascript or stylesheet you need to correct asset url manually.

Rails 3.1 asset pipeline not seeing files

We're upgrading our app from Rails 2 to Rails 3.1, and I'm having trouble with the asset pipeline.
I've got the following in my config/application.rb:
if defined?(Bundler)
Bundler.require *Rails.groups(:assets => %w(development test))
# Bundler.require(:default, :assets, Rails.env)
end
# Enable the asset pipeline
config.assets.enabled = true
# config.assets.prefix = "/assets"
config.assets.paths << "#{Rails.root}/public/images"
config.assets.paths << "#{Rails.root}/public/stylesheets"
config.assets.paths << "#{Rails.root}/public/javascripts"
config.assets.version = '1.0'
And then this in development.rb
# Do not compress assets
config.assets.compress = false
config.assets.debug = true
I know this isn't the desired behavior for the pipeline, but we are doing it this way to make sure that when we merge the upgrade back into our master branch, all the old files are accounted for properly.
I then have the following file, "all.css," in my public/stylesheets directory:
/*
*= require ezform
*= require jquery-ui-1.8.9.custom
*= require thickbox
*= require yui-upload
*= require styles
*/
I am calling it from within my layouts/application.html.erb file like so:
<%= stylesheet_link_tag "all" %>
Loading things up in a browser, however, I get no styles (or javascript, for that matter). Firebug and Chrome tell me that the .css and .js files are being looked for in "/assets" - it's like the pipeline isn't searching through everything and bundling it like it should.
The error looks like this:
GET http://localhost:3000/assets/jquery-dependent.js 500 (Internal Server Error)
If I move "all.css" into /app/assets, it still won't find it. Moving it into /assets stops the error, but the stylesheet doesn't compile and I still don't get any styles in my browser.
There's also a slew of errors that look like this in my log:
Started GET "/assets/defaults.js?body=1" for 127.0.0.1 at 2011-12-22 14:35:36 -0600
[2011-12-22 14:35:36] ERROR NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
/Users/kevin/.rvm/gems/ruby-1.9.2-p0#media3/gems/rack-1.3.5/lib/rack/handler/webrick.rb:71:in `service'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
cache: [GET /assets/defaults.js?body=1] miss, store
Served asset /defaults.js - 200 OK (1ms)
What am I missing?
sigh It was memcached. I tured it on (memcached -d) and now all my assets are appearing. I'm not sure why, so I'd love some explanation. Otherwise, it's working.
There are a while bunch of settings that need to be added into the development and application config files for the pipeline to work correctly.
Check out the last section of the pipeline guide for details of these.
Once you've done that I suggest that you change the manifest names to application.css and application.js as these are the default names and you'll run into fewer problems starting with those. Edit your question if it still does not work and I'll see if I can help after that.

pdfkit not rendering correctly in rails 3.1

I have followed the following railscast about adding pdfkit to an application, and I am having some issues with the generation of pdfs. Here are the following things that I have done:
I downloaded wkhtmltopdf via the homebrew package manager
brew install wkhtmltopdf
Then I added the pdfkit gem to my gemfile and ran the bundle install command. I added the following to my config/application.rb file
require 'pdfkit'
...
config.middleware.use PDFKit::Middleware, :print_media_type => true
I then changed my application layout file to include all stylesheet types.
If I run rake middleware, the command works and I can see the pdfkit middleware
When I try to append pdf to the end of my routes the application just hangs and I have to exit via the command line. If I create a link to the page I want to make into a pdf, it changes all of the markup so it looks like a corrupted file. (it looks like you opened a text file into a word processor or vice versa I can provide images if that helps) If I try to make css changes in my stylesheet they do not go into effect when I view them with the link to pdf. I am assuming that this has something to do with the new asset pipeline in rails has anyone else experienced this issue?
So I was right in assuming that my error had something to do with the asset pipeline, after doing some research it looks like you need to create a new initializer and add the following code:
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}