tmikoss / openlayers-rails

Other
13 stars 9 forks source link

style.css not getting precompiled #2

Open workmaster2n opened 11 years ago

workmaster2n commented 11 years ago

The gem works perfectly in development, but when I deploy to my production server I get an error that <domain>/assets/openlayers/theme/default/style.css 404 (Not Found). If I precompile the assets on my local machine, I notice that the folder assets/public/openlayers/theme/default only contains an img folder.

Rails 3.2.13 Bundler 1.3.5

ejanuska commented 11 years ago

I'm having this same issue. Tried relocating img and theme folders to vendor, vendor/assets, vendor/assets/javascripts.

proteantech commented 11 years ago

Make sure you are including the css in the asset pipeline either through application.css via require or through the config.assets.precompile property in either your production.rb or application.rb environment files. See this post for info on how to include all css/js:

http://stackoverflow.com/questions/7278029/rails-3-1-asset-precompilation-include-all-javascript-files

The README only instructs you to do the following:

Add //= require openlayers-rails to your app/assets/javascripts/application.js manifest file.

which handles pulling the JS into the application, but not the CSS. I believe the images are pulled in by default. Although I'm not quite sure how the mechanism is working for the JS since the gem-name is specified instead of the actual javascript filename, "OpenLayers.js". Would love to know this if anyone finds out.

UPDATE: Figured out my above question.

http://guides.rubyonrails.org/asset_pipeline.html#asset-organization

2.2.2 Using Index Files

Sprockets uses files named index (with the relevant extensions) for a special purpose.

For example, if you have a jQuery library with many modules, which is stored in lib/assets/library_name, the file lib/assets/library_name/index.js serves as the manifest for all files in this library. This file could include a list of all the required files in order, or a simple require_tree directive.

The library as a whole can be accessed in the site's application manifest like so: //= require library_name

This simplifies maintenance and keeps things clean by allowing related code to be grouped before inclusion elsewhere.

UPDATE2: I was wrong, the index mechanism isn't being used. A simpler mechanism is used in this project.

https://github.com/tmikoss/openlayers-rails/blob/master/app/assets/javascripts/openlayers-rails.js?source=c

This file simply includes the actual OpenLayer.js file.

workmaster2n commented 11 years ago

@proteantech Doesn't the file https://github.com/tmikoss/openlayers-rails/blob/master/lib/openlayers-rails.rb add the css to the list of files to be precompiled?

proteantech commented 11 years ago

@workmaster2n It appears you are correct. Are you resetting the "config.assets.precompile" anywhere? For example:

config.assets.precompile = [my.css]

May reset the assets to only precompile "my.css" and the work of the initializer in openlayers-rails.rb may be lost. Not sure on the order of how things get processed though, but I'm guessing you get the final say in your environment files and the gems are processed first. Comparing the format of the above code snippet to:

config.assets.precompile += [my.css]

Which would append to the current list.

I also suppose it's possible some other gem could be goofing up your precompile path. Try adding some logging in your environment file to output the precompile path and see what it looks like.

tmikoss commented 10 years ago

@workmaster2n is this still an issue?

workmaster2n commented 10 years ago

@tmikoss We changed up the style.css sheet in favor of themes, so we ended up having to modify the asset pipeline to load our custom css files. Not sure if we would run into this problem without those custom style sheets. I vote to close this issue and I'll reopen it if my future endeavors find the same issue.

bouldrini commented 10 years ago

Hi folks, i saw you are loading the style.css file like this: this.theme = OpenLayers._getScriptLocation() + 'theme/default/style.css'; which is well working for development mode, but since you have to precompile your assets for production this is failing because style.css is named something like this now: style-369f8e7755ad2408de863713ca68bacb.css

You can get rid of this by importing or requiring the file explicit. @import "openlayers/theme/default/style"; (in case you use sass) //= require (in case you dont)

Of course this is a hack, the 404 still occurs, but the map is displayed correctly.

rsalevsky commented 9 years ago

Is there any update? I use the latest version but it doesn't work in production mode and the solution from @RichardWieditz doesn't work too.

tmikoss commented 9 years ago

Please try using rails-assets-openlayers gem from https://rails-assets.org/ - I'm not actively maintaining this gem any more.