Rails 500 Error: application.css isn't precompiled - ruby-on-rails

I've got Rails running on Passenger with Apache on an Ubuntu linux box (ve) Server from Mediatemple. My app is giving me a 500 error (a Rails error, not an Apache error) when I try to load any page: http://www.mvngmtns.com
I saw an article about changing this line in config/environments/production.rb:
config.assets.compile = true
But this didn't solve my problem. Can anyone help?
My development.log:
Started GET "/" for 72.225.170.239 at 2012-06-29 15:28:43 -0700
Processing by HomeController#index as HTML
Rendered application/_logo.html.erb (0.6ms)
Rendered application/_navbar.html.erb (1.4ms)
Rendered home/index.html.erb within layouts/application (2.6ms)
Completed 500 Internal Server Error in 6ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>Moving Mountains<%= get_title %></title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8:
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___2841110860658336572_129641540'
app/controllers/home_controller.rb:6:in `index'
As requested, ran
rake assets:precompile --trace RAILS_ENV=production
touch /tmp/restart.txt
but still the same error. Here's what the trace said:
newguy#mvngmtns:/var/www/movingmountains$ rake assets:precompile --trace RAILS_ENV=production
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/rubies/ruby-1.9.2-head/bin/ruby /usr/local/rvm/gems/ruby-1.9.2-head#global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:non digest
I still have the same "500 - We're sorry, but something went wrong" in the browser, and cache: [GET /] miss in the apache log file.

After setting
config.assets.compile = true
you should also run:
rake assets:precompile --trace RAILS_ENV=production
See: rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)

I don't know details on Mediatemple, but perhaps you need to precompile your assets before deploying:
rake assets:precompile

A couple things:
check that the stylesheet actually gets compiled - it will be something like public/assets/application-XXX.css
Passenger looks for APP_DIR/tmp/restart.txt, not /tmp/restart.txt, so make sure you touch the file in the right place

Related

Problems with migration of Cassandra db on Ubuntu 14.04

When I making migration db Cassandra with command:
es#es:~/server-new$ rake ks2:migrate_old
After this I get error:
rake aborted!
SystemStackError: stack level too deep
Tasks: TOP => ks2:migrate_old => ks2:set_keyspace2 => ks2:configure2 => environment
(See full trace by running task with --trace)
When I start command: rake ks2:migrate_old --trace
I get error:
** Invoke ks2:migrate_old (first_time)
** Invoke ks2:set_keyspace2 (first_time)
** Invoke ks2:configure2 (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
SystemStackError: stack level too deep
/home/es/.rvm/gems/ruby-2.0.0-p353/gems/rake-10.4.2/lib/rake/task.rb:183
Tasks: TOP => ks2:migrate_old => ks2:set_keyspace2 => ks2:configure2 => environment
How to make migration work?

db:migrate:reset doesn't work with environment variables

The way I set up environment variables is like it was outlined here.
In other words I created a config/app_env_vars.rb file and put:
unless Rails.env.production?
ENV['DB_PASSWORD'] = 'password'
ENV['DB_USERNAME'] = 'username'
end
puts 'ECHO app_env_vars.rb'
In config/environment.rb I put:
app_env_vars = File.join(Rails.root, 'config', 'app_env_vars.rb')
load(app_env_vars) if File.exists?(app_env_vars)
puts "ECHO environment.rb"
right before Rails.application.initialize!
In database.yml:
development:
adapter: postgresql
encoding: unicode
database: my_app_development
host: localhost
pool: 5
password: <%= ENV['DB_PASSWORD'] %>
test:
adapter: postgresql
encoding: unicode
database: my_app_test
host: localhost
pool: 5
password: <%= ENV['DB_PASSWORD'] %>
When I run tasks such as bundle exec rake db:migrate and bundle exec rake db:reset it works fine but when I run bundle exec rake db:migrate:reset it will fail displaying:
fe_sendauth: no password supplied
.
.
.
Couldn't drop my_app_development
fe_sendauth: no password supplied
.
.
.
Couldn't drop my_app_test
fe_sendauth: no password supplied
ECHO app_env_vars.rb
ECHO environment.rb
Usually when I run bundle exec rake db:migrate (and db:drop) it will first display the ECHO parts and then do the task and out put the log. But in the case of the db:migrate:reset it won't initialize the environment variables until after the task.
When in database.yml I put the actual passwords rather than the env variables then the
db:migrate:reset works with no problem.
Here is rake db:migrate:reset with --trace option
** Invoke db:migrate:reset (first_time)
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:drop
fe_sendauth: no password supplied
.
. # gem trace stuff...
.
Couldn't drop my_app_development
fe_sendauth: no password supplied
.
. # gem trace stuff...
.
Couldn't drop my_app_test
** Invoke db:create (first_time)
** Invoke db:load_config
** Execute db:create
fe_sendauth: no password supplied
.
. # gem trace stuff...
.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"my_app_development", "host"=>"localhost", "pool"=>5, "password"=>nil}
fe_sendauth: no password supplied
.
. # gem trace stuff...
.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"my_app_test", "host"=>"localhost", "pool"=>5, "password"=>nil}
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
ECHO app_env_vars.rb
ECHO environment.rb
** Invoke db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
** Execute db:migrate:reset
Here is the --trace for rake db:reset
** Invoke db:reset (first_time)
** Invoke environment (first_time)
** Execute environment
ECHO app_env_vars.rb
ECHO environment.rb
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:reset
** Invoke db:drop (first_time)
** Invoke db:load_config
** Execute db:drop
** Invoke db:setup (first_time)
** Invoke db:schema:load_if_ruby (first_time)
** Invoke db:create (first_time)
** Invoke db:load_config
** Execute db:create
** Invoke environment
** Execute db:schema:load_if_ruby
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
-- enable_extension("plpgsql")
-> 0.0772s
-- create_table("users", {:force=>true})
-> 0.0795s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true, :using=>:btree})
-> 0.0406s
-- initialize_schema_migrations_table()
-> 0.0829s
** Invoke db:structure:load_if_sql (first_time)
** Invoke db:create
** Invoke environment
** Execute db:structure:load_if_sql
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
** Execute db:abort_if_pending_migrations
** Execute db:setup
In the case of db:reset the ** Execute environment part is done before any executions, while with db:migrate:reset the ** Execute environment is done after a few executions
The reason why this setup (setting env variables in a file then load them trough environment.rb) doesn't work is because active record can be used outside rails therefore now every task runs with initialized rails environment.
A better solution is to use gems like figaro or dot-env which will load with every rake task. How exactly is that done with those gems I am not sure but if I get into it and find out I'll post here.

My Capistrano does not set the RAILS_ENV variable

My Capistrano deployment does not set the RAILS_ENV variable when running the bundle command. I don't understand why.
My Gemfile is :
source 'https://rubygems.org'
ruby '2.1.3'
gem 'capistrano', '~> 3.2.1'
gem 'capistrano-rails', '~> 1.1.1'
My deploy.rb :
set :stage, :production
set :rails_env, 'production'
set :bundle_flags, '--deployment'
set :bundle_env_variables, { rails_env: "production" }
namespace :sphinx do
desc "Index Sphinx"
task :index do
on roles(:app) do
within release_path do
execute :rake, "rake ts:index"
end
end
end
When running :
➜ ansible-sharetribe git:(master) ✗ bin/cap production sphinx:index --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_rails_env
** Invoke sphinx:index (first_time)
** Execute sphinx:index
INFO[3ca70ab5] Running bundle exec rake rake ts:index on www.myapplication.com
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host www.myapplication.com: rake exit status: 1
rake stdout: Nothing written
rake stderr: Digest::Digest is deprecated; use Digest
rake aborted!
NameError: uninitialized constant Annotate
If I write :
execute :rake, "rake ts:index RAILS_ENV=production"
it works. Why is RAILS_ENV=production not set automatically?
You can use this syntax in your task
execute :rake, "rake ts:index", "RAILS_ENV=#{fetch :rails_env}"
I have the same problem.
I ran rake secret and got "NameError: uninitialized constant Annotate" error.
After i set RAILS_ENV=production, it worked like charm.
I dont know why RAILS_ENV wasnt set but BTW thanks so much.
Saved me a lot of time

rake db:create gives undefined method `[]' for nil:NilClass error

Postgres 9.3, Ruby 2.1.0
rake db:create isn't making a test database. I already have a production database. I tried using RAILS_ENV=test rake db:create to force it but it returns "test database is not configured.
My database.yml ->
development:
adapter: postgresql
  database: app_prod
  host: localhost
test: &test
  adapter: postgresql
  database: app_test
  host: localhost
cucumber:
<<: *test
production:
  adapter: postgresql
 database: app_prod
  host: localhost
So it is configured. I also tried just using a console createdb app_test to create my test database but I receive the same error when I try to run rake db:test:prepare.
Anyone have any ideas?
this is --trace on db:create:all
** Invoke db:create:all (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create:all
rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:189:in `block in each_local_configuration'
this is trace on db:test:prepare
** Invoke db:test:prepare (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:test:purge
rake aborted!
undefined method `[]' for nil:NilClass
/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.0.3/lib/active_record/tasks/database_tasks.rb:137:in `purge'
Try running this in console
ActiveRecord::Base.configurations
You should get your database configurations.
Line 3 in this method(Line 189 in github) is failing in your case because configuration is nil
def each_local_configuration
ActiveRecord::Base.configurations.each_value do |configuration|
next unless configuration['database']
if local_database?(configuration)
yield configuration
else
$stderr.puts "This task only modifies local databases. #{configuration['database']} is on a remote host."
end
end
end

Application.css isn't precompiled error 500 rails

I have an error with rails + nginx + unicorn in production
ActionView::Template::Error (application.css isn't precompiled):
I'm trying to deploy clean rails app with sqlite3.
When i visit http://cayennepower.ru/posts i have We're sorry, but something went wrong error.
On front page the static welcome page works good.
In my app/log production.log i have such errors
Started GET "/posts" for 127.0.0.1 at 2012-12-12 06:47:48 +0100
Processing by PostsController#index as */*
Rendered posts/index.html.erb within layouts/application (0.4ms)
Completed 500 Internal Server Error in 3ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>CleanRails</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___741543018_80365330'
app/controllers/posts_controller.rb:7:in `index'
in config/enviroments/production.rb i placed
config.assets.compile = true
config.assets.precompile += %w( application.css )
i've run rake assets:precompile --trace RAILS_ENV=production
The trace log is
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rvm/rubies/ruby-1.9.3-p327/bin/ruby /usr/local/rvm/gems/ruby-1.9.3-p327/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
but i still has this error
my nginx.conf is
upstream cayennepower.ru {
server unix:/home/sites/cayennepower.ru/www/tmp/sockets/unicorn.sock;
# server 127.0.0.1:3000 fail_timeout=0;
}
my domain.conf file is
server {
listen 80;
server_name cayennepower.ru;
root /home/sites/cayennepower.ru/www/public;
try_files $uri/index.html $uri #unicorn;
location #unicorn {
#if (!-f $request_filename) {
proxy_pass http://cayennepower.ru;
break;
#}
}
}
Thank you very much for help guys!

Resources