I am deployed my rails project to the AWS. I have following in my Gemfile:
group :development do
gem 'capistrano'
gem 'capistrano3-puma'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-bundler', require: false
gem 'capistrano-rvm'
end
In my production.rb
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = true
config.assets.digest = true
However, when I load my application in the web browser I see in the console that my application-xxxxxx.css and application-xxxxxx.js gives 404 not found error. Also, when I go to the server and look for the file in public/assets/ folder, the application-xxxxxx.js is present there.
Can anyone help me with this?
The problem was not in the asset compilation and deployment. I had to change the path from root /home/deploy/portal/public; to /home/deploy/portal/current/public; in nginx configuration file /etc/nginx/sites-enabled/default.
Related
I am getting the error when starting the server rails s in my local environment.
I tried to google , but all these capistrano Dont know how to build tasks are all deploy related, not when starting server in local environment.
I am not sure either whether its a rails or capistrano issue.
Here is the link of the trace. Gist.
Any help is appreciated!
application.rb
You probably have Capistrano-related gems in your Gemfile but have not marked them as require: false. As a result, when Rails boots up, it tries to load all of that Capistrano code, which is not how Capistrano is intended to be used.
In your case it looks like the capistrano-gitflow gem is the culprit. Always use require: false for it and all other Capistrano-related gems in the Gemfile, like this:
gem "capistrano", "~> 3.10", require: false
gem "capistrano-bundler", require: false
gem "capistrano-rails", require: false
The fact that this is not explained in the Capistrano documentation is an oversight that I will try to get corrected.
I am currently following 'Ruby on Rails Tutorial' by Michael Hartl. On Chapter 3 when I try to deploy the working sample app with Heroku it is rejected, and even though I fully understand the error message I do not know how to correct it. Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
And here is the file where the issue originates which is config/environments/development.rb:
SampleApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
The errors I get are attempting 'git push heroku master':
Running: rake assets:precompile
rake aborted!
NoMethodError: undefined method `configure' for #<SampleApp::Application:0x007fc7f03f7298>
and after a long list of paths I get:
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:some-name.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:some-name.git'
Any idea how to fix this please? I really would like to get deployments working under Ubuntu.
Thank you!
By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line:
config.serve_static_assets = true
Have a read through this documentation on heroku as well - https://devcenter.heroku.com/articles/rails-4-asset-pipeline
Hope it helps. :)
Rails 4
The problem is a common issue with the Hartl tutorial - it derives from using Rails 3 in the tutorial, and a later version being used widely now
I tried looking for references on this, but I couldn't. I've found them somewhere before - will have another look for you.
Anyway, in Rails 4, need this (we have this in our Rails 4 apps):
#config/environments/development.rb
Rails.application.configure do
This sets the configure code block for the correct object. I think Rails changed some of its core functionality in 4.0+, which is why you're getting the issue now
I'm trying to push a Rails application to AppFog and I keep getting a 301 error.
It gets to Staging, so it shows up on my AppFog account, but refuses to activate. Trying to update it succeeds, but has the same problem where it won't activate and only shows a 404 error.
Here is the message text:
$ af push RubyMongoGranny --runtime=ruby193
Would you like to deploy from the current directory? [Yn]:
Pushing application 'RubyMongoGranny'...
Creating Application: OK
Binding Service [ruby_mongo_granny]: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (236K): OK
Push Status: OK
Staging Application 'RubyMongoGranny': ..........Error 310: Staging failed: 'Staging task failed:
Staging plugin failed: /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:325:in `log_and_raise_error': Error resolving Gemfile: Error parsing Gemfile: /tmp/d20130401-19438-h0d0st/Gemfile not found (RuntimeError)
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:50:in `specs'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:103:in `gem_info'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_support.rb:86:in `gem_info'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:188:in `rails_version'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:199:in `precompile_assets'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:85:in `block in stage_application'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:76:in `chdir'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:76:in `stage_application'
from /opt/cloudfoundry/vcap/stager/bin/run_plugin:19:in `<main>'
My gemfile looks like:
source 'https://rubygems.org'
gem 'rails'
gem 'mongo_mapper'
gem 'bson_ext'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'cloudfoundry-jquery-rails
==UPDATE==
Changed
config.server_static_assets = false
to
config.server_static_assets = true
and precompiled my assets?
bundle exec rake assets:precompile
but it still gives me the same error.
Changed
gem 'jquery-rails'
to
gem 'cloudfoundry-jquery-rails'
still no success
Did you change in your config/environments/production.rb
config.server_static_assets = false
to
config.server_static_assets = true
and precompiled your assets?
bundle exec rake assets:precompile
Also, for Ruby 1.9 AppFog requires a tweak to the jquery-rails gem. Remove or comment out gem 'jquery-rails' and add gem 'cloudfoundry-jquery-rails', like so:
# gem 'jquery-rails'
gem 'cloudfoundry-jquery-rails'
Further documentation here.
Didn't really come up with a good solution for this problem. However, I created a brand new rails app and moved all of my files from the old one to the new one. Now it will push to AppFog.
I did a diff of the directory, but all the differences are just log files, the app name, and the readme file. Nothing really stands out as a possible cause of the error.
I've got 3.1 application.
At the beginning i'd added
config.assets.enabled = false
not to use pipeline.
Now i've commented this line. restart server.
I've got app\assets\javascripts\application.js
In my layout view I use:
<%= javascript_include_tag "application" %>
my page tries to load "javascripts/application.js" not assets/application.js
What may be wrong in my configuration?
gemfile (unnecessary removed):
gem 'rails', '3.1.1'
gem 'sqlite3'
# Asset template engines
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Rather than commenting out the line, have you tried leaving it in and making it config.assets.enabled = true instead? It looks like the default value will always be false, so you need to explicitly set it to true.
If you turn the pipeline off then the Rails helpers revert to the old paths to javascript and CSS - in those folders in the /public directory. If you don't want to use the pipeline then you have to use those folders instead, not the assets folder ones.
Dylan is correct - you have to explicitly enable the pipeline, and this is the default for a new generated app.
I've got html5-rails and compass-html5 working in devlopment on rails 3.1 but when I run my app in production mode and try to visit my homepage, I get the following:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
polyfills.js isn't precompiled
The thing is that localhost:8080:/assets/polyfills.js does display. I suspect there is a problem with my methods:
Steps to reproduce:
1 Create new rails app with home controller, index action and set up a root route and delete public/index.html and views/layouts/application.html.erb
2 Add following to Gemfile
gem 'rails', '~> 3.1.0'
gem 'unicorn'
group :assets do
gem 'compass', "~> 0.12.alpha.0"
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass-html5', :git => 'https://github.com/sporkd/compass-html5.git'
gem 'html5-rails', :git => "https://github.com/sporkd/html5-rails.git"
end
3 Run rails g html5:install to create /config/compass.rb file
4 Create /config/initializers/sass.rb containing following code:
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
end
5 Run RAILS_ENV=production bundle exec rake assets:precompile
6 Run unicorn -E production (or rails s -e production if you're on webrick) and visit root url
7 Observe bug
The correctly minified respond-md5.min.js and modernizr-md5.min.js are present in /public/assets. The compiled js code does appear when I visit localhost:8080/assets/modernizr.min.js. The server error is thrown when I try to visit my homepage.
I suspect there is an error in my method. I have asked the very same question here on github.
I managed to fix this by adding polyfills.js to application.rb
config.assets.precompile += %w( polyfills.js )
i just got the same error, and the issue was that my file was missing...