I'm trying to port my rails 3.0.7 project to rails 3.1
I have Phusion Passenger running on nginx + rvm.
There is config.assets.enabled = true in my application.rb file.
I created empty rails 3.1 project and copied my app directory, routes.rb and application.rb files over it. I moved everything from public to app/assets (app/assets/stylesheets etc).
When I'm trying to access assets (application.css/application.js), I'm getting 404 not found error, but I can see them in app/assets/stylesheets/application.css and app/assets/javascripts/application.js.
Help me please.
UPD: Thanks to Devin M for the idea, I removed css,js,gif,png and jpg extensions from nginx.conf ("serve static files directly") and everything started to work.
I came to this question with a similar problem (everything was giving a 404) I found that Rails 3.1.0.rc4 has a problem with gem 'sprockets'
In your Gemfile set:
gem 'sprockets', '= 2.0.0.beta.10'
Note: you may have to manually override your Gemfile.lock before you bundle install
Usually this is a problem with the nginx config not set up to serve things correctly. Double check your config files.
Related
I deployed a rails application with Dokku. Everything went fine except that all my assets including images returns a 404 error.
I really don't know how to debug this.
For dokku it is simple to add:
dokku config:set <your-app> RAILS_SERVE_STATIC_FILES=true
I had exact same issue and adding the following gem solved it:
gem 'rails_12factor', group: :production
That's the official way of dealing with that issue on Heroku for Rails 3 and 4 (and that gem is made by Heroku team as well).
On rails 5, try making the changes in production.rb that are suggested on this page rails_12f
Finally I just added this :
config.serve_static_files = true
in environements/production.rb
Note: flag deprecated in Rails 5.0 in in favor of config.public_file_server.enabled
I have searched around and can't rectify the situation based on the responses to other similar questions. I seem to have broken the asset pipeline somehow but can't seem to figure out how.
None of my assets are being loaded at all; rails seems to just be ignoring my manifest files. When I inspect my page in firebug, only the 'non-compiled' text inside my manifest files (both js and css) is being displayed - almost as if the asset pipeline wasn't even enabled.
I deleted the contents of public/assets since I was adding a new file to the manifest which seemed to start this behavior.
Current configuration:
environments/development.rb
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
application.rb
# Enable the asset pipeline
config.assets.enabled = true
config.assets.manifest = config.root
# Add extra assets for precompiling
config.assets.precompile += ['admin.js', 'admin.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
I had the same issue. You can still use Ruby 2.1.2, just upgrade rails to latest 3.2.x version - it's 3.2.22
Gemfile:
gem 'rails', '3.2.22'
And run:
$ bundle update rails
The issue was caused by using an incompatible version of ruby. I was using version 2.1.2 which lead to unusual behavior from the sprockets gem (which powers the asset pipeline). This was fixed by downgrading to ruby 1.9.3. I haven't done any experimentation for fear of breaking it again but maybe this has been addressed in later versions of sprockets. I am using sprockets 2.1.3.
See: Rails 3.2.8 Application.js and Application.css are not working as expcted
Always remember two things when you want to handle Rails asset pipleline:-
if you want all you newly created js/css to autoinclude in application.js/css,pls add them in...
ELSE
IF you dont wont to add in manifest file(application.js/css) then use precompile directive in yuur environment file.
config.assets.precompile=%w(custom.css,custom2.js...etc)
so make sure you have either of these...
===========for example=-=============
suppose you have new css/js file:-
custom.css inside
app/assets/stylesheets/
so you can include in
application.css
// = require 'custom'
OR
use precompile directive:-
config.assets.precompile += %w( custom.css )
and then reference it like you always do
stylesheet_link_tag "custom"
same applies for js also
I just spent a few hours troubleshooting this issue (in 2017!) and it turned out I just needed to remove the gem active_reload. Updating rails and ruby was having no effect for me. The thread where I found that gold is here:
https://github.com/rails/rails/issues/2715
I can't get the foundation-icons to show in production-enviroment (deployment) while in development it works just fine.
When I start the server in production-mode via nginx and the gem puma, basically the only error I get is this:
ActionController::RoutingError (No route matches [GET] "/stylesheets/foundation-icons.css")
I've tried to add this to config/enviroments/production.rb:
config.assets.precompile += %w( vendor/foundation.scss )
and I precompiled using RAILS_ENV=production
I'm using the latest version of foundation:
gem 'foundation-rails', github: 'ahacking/foundation-rails'
Using ruby 2.0.0.p353 and Rails 4.0.2.
Edit:
Foundation-icons has no real relation to the foundation gem. (I wasn't the guy who implemented it in the application)
Edit 2:
Added config.assets.compile = true in config/environments/production.rb witch removed the error, however the icons are still missing.
I found a gem for foundation-icons that works like a charm
https://github.com/zaiste/foundation-icons-sass-rails
Error message of my server
A NameError occurred in..
uninitialized constant CarrierWave::Video app/uploaders/video_uploader.rb:7:in
<class:VideoUploader>'
video_uploader.rb:7 => include CarrierWave::Video
INFO :
In my local, it works(development & production mode)! But after deploy to server, occur that error.
But in my server rails c production,Input 'include CarrierWave::Video' then Rails Console print not 'NameError: uninitialized constant..' but 'Object'. This means 'include CarrierWave::Video' succeeded!!
Of course, these gem(gem 'carrierwave' , gem 'carrierwave-video') is in my Gemfile and Gemfile.lock and bundle install success.(when deploy) So in my_app/shared/bundle/ruby/2.0.0, GEM_HOME & GEM_PATH of my app, exist these gems
I think 'include' doesn't work. because Like this, i have been met this error at line 'include CarrierWave::RMagick' when using gem 'rmagick' to resize image file uploaded.
Of course, this is not solved yet..
Purely CarrierWave removed line 'include ~~' works well (ex : Image upload not resized..)
nginx + unicorn, linux ubuntu 12.04
Please help me.. T^T
i dont know why 'include CarrierWave::Video' not work in .rb file but work in rails console..
ADDED :
'require' about these gems not exist in my code(in application.rb.. etc..),
(require 'carrierwave/video'.)
If add "require 'carrierwave/video'" to application.rb below require 'rails/all',
occured my application is now worked all. If add to video_uploader.rb and I request page using video_uploader , then occur error cannot such file bulabula..
This error caused by your server didn't reload the module.
Just restart your rails server, and everything will go right.
Make sure you are loading CarrierWave after loading your ORM.
If you added gem 'carrierwave' do this rails generate uploader UPLOADER_NAME
I have installed ajax_pagination gem from https://github.com/ronalchn/ajax_pagination
When I restart my server i get this message
couldn't find file 'history'
(in
/Users/user/.rvm/gems/ruby-1.9.3-p362/gems/ajax_pagination-0.6.3/lib/assets/javascripts/ajax_pagination.js.erb:3)
and inserted calls in assets manifests, rails version is 3.2.8
I had tried installing a history gem ( https://github.com/philostler/historyjs-rails ) or adding history.js to assets but nothing helps
Thanks for any help!
I had the same issue, all you need to do is:
Add gem 'jquery-historyjs' to your Gemfile,
Run bundle install
Then rails generate historyjs:install
This appears to be a bug in the jquery-historyjs gem, which ajax_pagination depends on. You may want to report an issue on their github repo.
As a work-around, you could create a blank history.js file in app/assets/javascripts and try bringing in historyjs-rails.